The original way to send Ajax to action, you will encounter get,post different, because of the ContentType problem, ContentType must be text/html,struts get the InputStream to have value! And the default jquery to send Ajax using the contenttype is application/x-www-form-urlencoded; Charset=utf-8, if manually set to JSON format to send, then STRUTS2 will not get the data, so in the case of post submission without specifying ContentType, with the default on the line, this is not the same as SPRINGMVC, SPRINGMVC send JSON to specify ContentType as ' Application/json;charset=utf-8 ', and JSON is a fully formatted string, but struts2 not only contentType support text /html, and send data does not need to be converted to JSON string, directly send JSON object can, a bit of a pit AH
When you output JSON in the original way, you can use Fastjson, which is relatively efficient, but the following points are important to note:
1. Fields that do not require JSON conversion, add @jsonfield (Serialize=false) to the Set method
2, mutual Reference object, must have an object property set method plus @jsonfield (serialize=false), in case of circular reference
3, Fastjson conversion data cannot use Hibernate's Load method to obtain data, report stack overflow error
4, the list in the same object for the JSON conversion, the default next object will be displayed as a reference to the previous ref, need to set Fastjson to the same object JSON conversion
String jsonstr = json.tojsonstring (list, serializerfeature.disablecircularreferencedetect);//After closing reference detection
Struts2 Send Ajax several questions (without using Struts2-json-plugin case)