怎么用springMVC输出json数据到jsp页面
3个回答
2013-03-28
展开全部
这个回答对的呀,关键就是那句out向JSP输出json对象,然后你可以在JSP页面获取。楼上这个用的不是struts2吧和Servlet API紧耦。
推荐于2017-10-01
展开全部
throws Exception {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
request.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
UsersForm usersForm = (UsersForm) form;
int pageNo = usersForm.getPageId();
List<Users> user = userBiz.findAllUserRole(pageNo);
JSONArray json = new JSONArray();
for(Users u:user){
JSONObject temp = new JSONObject();
temp.put("userID", u.getUserId());
temp.put("userUname", u.getUserName());
temp.put("userPass", u.getUserPassword());
temp.put("userTrueUname", u.getTrueName());
temp.put("userBirthday", u.getBirthday());
temp.put("userSex", u.getSex());
temp.put("userEmail", u.getEmail());
temp.put("userPhone", u.getHomePhone());
temp.put("userRole", u.getRole().getRoleName());
json.add(temp);
}
out.print(json.toString());
return null;
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
request.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
UsersForm usersForm = (UsersForm) form;
int pageNo = usersForm.getPageId();
List<Users> user = userBiz.findAllUserRole(pageNo);
JSONArray json = new JSONArray();
for(Users u:user){
JSONObject temp = new JSONObject();
temp.put("userID", u.getUserId());
temp.put("userUname", u.getUserName());
temp.put("userPass", u.getUserPassword());
temp.put("userTrueUname", u.getTrueName());
temp.put("userBirthday", u.getBirthday());
temp.put("userSex", u.getSex());
temp.put("userEmail", u.getEmail());
temp.put("userPhone", u.getHomePhone());
temp.put("userRole", u.getRole().getRoleName());
json.add(temp);
}
out.print(json.toString());
return null;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-03-28
展开全部
我现在也遇到这个问题了,可惜没人解答啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询