Record struts2 JSON plugin handling of string array types

Source: Internet
Author: User

In the current project, a developer defines a property of a string array type in action that needs to be returned to the page in JSON format ( regardless of whether the design is optimal ).

The result is that it is not always possible to get this property in the Ajax success method when doing page debugging. background action debugging found that the array has been correctly assigned, get

method is not a problem, the action-related code is as follows:


Private string[] tracelist;private String unitname; .... Public String Querytrace () {    unitname = "testname";    tracelist=tranmanager.gettracelist (Traceno);    return "Querytrace";} ... Public String Getunitname () {    return unitname;} Public string[] Gettracelist () {    return tracelist;}

The corresponding action configuration in the struts configuration file adds the following configuration:


<result name= "Querytrace" type= "JSON" > <param name= "includeproperties" >tracelist,unitname</param ></result>

The successful callback method in Ajax gets to the Tracelist object is always an empty array, viewing the STRUTS2 manual finds that


The includeproperties that is declared in the result of the Struts JSON plugin, for a string array or an array of primitive types, should be as follows:


<result name= "Querytrace" type= "JSON" > <param name= "includeproperties" >^tracelist\[\d+\],unitname</ Param></result>

It is also important to note that if excludeproperties and includeproperties are used at the same time, the precedence of the former is higher than the latter if there is a conflict.

Give us a link to the official struts file.







Record struts2 JSON plugin handling of string array types

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.