如何从 jsp 页面中的 json 输出而不是 java 代码中提取用户详细信息?
我的 ${users.user.firstname} 等不起作用。
代码运行良好,问题是我无法提取 json 列表。
@RequestMapping(value = "asjson", method = RequestMethod.GET)
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public String getAsJson(ModelMap model)
{
Client client = Client.create();
WebResource service = client.resource(getBaseURI());
String userAsJson = service.path("user/").path("getall").accept(MediaType.APPLICATION_JSON).get(String.class);
model.addAttribute("json", userAsJson);
return "asjson";
}
private static URI getBaseURI()
{
return UriBuilder.fromUri("http://localhost:8080/xxxxxxx/").build();
}
在 jsp 页面中,我使用 El 标签通过 foreach 循环打印用户详细信息,并且:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4 /loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<body>
<c:forEach var="users" items="${json}">
${users}
</c:forEach>
清单的一部分是:
{
"user": [
{
"userid": "1",
"firstname": "xxxxx",
"lastname": "xxxxxxx",
"username": "xxxxxx",
"password": "xxxxxx",
"email": "xxxxxxx",
"isEnabled": "true",
"address": {
"street": "xxxxxxxxx",
"zipcode": "xxxxxxx",
"city": "xxxxxxx"
},
"roles": [
{
"roleid": "1",
"rolename": "ROLE_ADMIN"
},
{
"roleid": "2",
"rolename": "ROLE_USER"
}
]
},
{
"userid": "2",
"firstname": "jesica",
"lastname": "biel",
"username": "jesica",
"password": "biel",
"email": "jesica@sex.se",
"isEnabled": "true",
"address": {
"street": "sexstreet",
"zipcode": "66666",
"city": "sexistan"
},
"roles": {
"roleid": "5",
"rolename": "ROLE_USER"
}
}
]
}
谢谢