如何从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"
}
}
]
}
谢谢