@Action(value = "/HealthtypeAction", params= { "contentType", "text/html" })
@Override
public String execute()
{
List<Healthtype> typeList = healthtypeService.findAll();
int total=typeList.size();
//httpServletRequest.setAttribute("type_LIST", typeList);
try {
httpServletResponse.setCharacterEncoding("UTF-8");
PrintWriter out = httpServletResponse.getWriter();
JSONObject jsonobj = new JSONObject();
JSONArray jsonArray = new JSONArray();
List<Healthtype> hlist=healthtypeService.getType(page,rows);
int count=hlist.size();
for (Healthtype hos : hlist) {
System.out.println(hos.getId());
jsonobj.put("id", hos.getId());
jsonobj.put("msgtype", hos.getMsgtype());
jsonArray.add(jsonobj);
Map<String, Object> json = new HashMap<String, Object>();
json.put("total", total);// total键 存放总记录数,必须的
json.put("rows", jsonArray);// rows键 存放每页记录 list
jsonobj = JSONObject.fromObject(json);// 格式化result一定要是JSONObject
}
System.out.println("count=" + jsonobj.size());
out.print(jsonobj);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
return SUCCESS;
}
action中json数据的运用举例
最新推荐文章于 2014-04-24 17:23:00 发布