The JSON plugin in 13-STRUTS2 uses

Source: Internet
Author: User

How to handle asynchronous commit (Ajax) in Struts2 1. Original:


HttpServletResponse response = Servletactioncontext.getresponse ();
Response.getwriter (). Write ("Hello" + msg);
Response.getwriter (). Close ();


2. You can use the JSON plug-in provided in STRUTS2


1. Import the JSON plug-in package
Struts2-json-plugin-2.3.15.1.jar under the Struts2 lib package.

2. Configure in the Struts.xml file
1.<package extends= "Json-default" >
2. Set the view <result type= "JSON" >

When this is set, the Valuestack stack top data is converted to JSON.
For our program, the action object is converted to JSON.


<param name= "root" >p</param> if not set, it can be understood to convert the entire action into JSON data. That is
The GetXXX method that is provided in the action is one of the properties in JSON.

If Root is set, only the specified data is converted to JSON.

--------------------------------------------------------
How do I set an object that is converted to JSON to contain no specific attributes?

1. @JSON (Serialize=false) set on the GetXXX method
2. You can also complete the interceptor via the JSON plugin.
<param name= "Includeproperties" >ps\[\d+\]\.name,ps\[\d+\]\.price,ps\[\d+\]\.count</param>

The JSON plugin in 13-STRUTS2 uses

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.