3 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊
如果你能夠返回json,這就說(shuō)明struts與json的插件是沒(méi)有問(wèn)題的,一般情況下,json的返回常常使用field來(lái)指定要返回的域,這樣的話就需要做一個(gè)封裝。你那樣寫(xiě)也是可以的,但是最終的json格式可能會(huì)改變,還是用瀏覽器直接訪問(wèn)以下這個(gè)action,看看最終返回的是什么吧

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊
下面是我寫(xiě)的
p
后臺(tái)部分代碼
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(); }
可以參考一下!
添加回答
舉報(bào)