last night encountered a bug, is the AJAX call Struts2 inside the method to obtain the JSON problem, although the problem is not solved, but a variety of Baidu, after the discovery of Stuts2 and Ajax interactive understanding and deep.
One, if you set the action to return the result as a JSON type
For example, if you want this action to return the result as JSON, first specify that the package inherits as Json-default, and then, in result, indicate type= "JSON".
The param parameter can also be added to the <result> node to specify the parameters for serialization: Where to start serialization, who to serialize, who to serialize ... For example, the root node of the configuration serialization is success, and if not configured, all properties that provide the get*** () method in the action are serialized by default. If it is, it is serialized down from Root.
two, some common configurations in action
If Root is not configured in the configuration file, you can do so on a method that does not require serialization:
After this annotation is added, the serialization of get** () is ignored. In addition, you can specify the serialized format and name in @json.
third, the object that implements the serializable interface
In General serialization, a non-static member variable that provides a Get method is serialized by default. However, you can specify properties that do not require serialization by using the keyword transient.
but for classes that implement the Externalizable interface, this keyword is useless.
Four, some pits of Struts2+ajax
1, each error, STRTUS2 error page information will be returned to Ajax, and is into the Ajax success method, (⊙﹏⊙) b ...
2, for beginners, not familiar with JSON, and do not see the JSON specific conversion process of the people, can only rely on guessing serialization when the error.
Struts2+ajax getting JSON data