struts2.3 action returns JSON data error during debugging
End-of-json-plugin jar package version inconsistency causes
Struts2-core-2.3.16.3.jar
Struts2-json-plugin-2.3.16.jar
Struts2-spring-plugin-2.3.16.3.jar
Xwork-core-2.3.16.3.jar
The action returns the JSON format in the following way: (to the Internet)
1. The traditional way JSON output httpservletresponse response = This.getresponse (); Response.setcontenttype ("application/json;charset= Utf-8 "); Response.setcharacterencoding (" Utf-8 "); PrintWriter pw = Response.getwriter (); String str = jsonarray.fromobject (list). toString ();p w.write (str);p W.flush ();p w.close (), 2.struts is available on the page Configuration mode struts.xml:<package ... extends= "Json-default" ><action name= "xxxxx" > <result type= "JSON" Name= "Success" > <param name= "root" >jsonMap</param> </result></action> Xxx.action:Map jsonmap;set...get...//generate set, Get Method method inside: Jsonmap = new hashmap<string object> (); Jsonmap.put ("List ", list); page: callback function: function (result) { var list = result.list; for (Var i=0;i<list.length;i++) { var name = list[i].name;//assumes list[i] There is a property name;} }
Reference:
Http://blog.sina.com.cn/s/blog_64e467d60101i8ez.html
Http://www.cnblogs.com/doit8791/p/4294276.html
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Struts2 Java.lang.ClassNotFoundException:org.apache.commons.lang.xwork.StringUtils