Struts2+ajax getting JSON data

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.