发现在项目中没有引用struts2-Json-plugin的jar包然后struts2中有get 方法的都能获取然后使用了如下的方法dataRows.*,curPage,totalPages,totalRecordstruefalse我不想返回那么多 按我需要的去返回 但是前台不能得到内容,是否是因为struts2-Json-plugin包的问题 ?
3 回答

PIPIONE
TA贡献1829条经验 获得超9个赞
如果你能够返回json,这就说明struts与json的插件是没有问题的,一般情况下,json的返回常常使用field来指定要返回的域,这样的话就需要做一个封装。你那样写也是可以的,但是最终的json格式可能会改变,还是用浏览器直接访问以下这个action,看看最终返回的是什么吧

弑天下
TA贡献1818条经验 获得超8个赞
下面是我写的
p
后台部分代码
HttpServletRequest request = ServletActionContext.getRequest();
// HttpServletResponse response=ServletActionContext.getResponse();
HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
String orgId = request.getParameter("orgId");// 获取组织id
List<Person> list=personService.querySortPerson(orgId); PrintWriter out = null; try { response.setContentType("text/plain"); response.setCharacterEncoding("utf-8"); out = response.getWriter(); out.write(JSONArray.fromObject(list).toString()); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); }
可以参考一下!
添加回答
举报
0/150
提交
取消