Struts2-method of uploading JSON data to the foreground from the background by Action (a) __js

Source: Internet
Author: User

This method automatically converts the data into JSON data and passes it to the page via Struts2 Interceptor.

Jar Package to import: Struts2-json-plugin-2.3.20.jar

Foreground JSP page:

<table id= "DG" title= "My Users" class= "
       easyui-datagrid" style= "width:700px;height:250px" url= "Get_user" Toolbar= "#toolbar" pagination= "true"
       rownumbers= "true" fitcolumns= "true" singleselect= "true" >
  < thead>
  <tr>
    <th field= "FirstName" width= "" >first name</th> "<th field=
    " LastName "Width=" >last name</th> <th field=
    "Phone" width= "M" >Phone</th>
    <th field= "Email" width= ">Email</th>
  </tr>
  </thead>
</table>"

Where the URL is action. The return value of the URL must be a JSON type.

Struts.xml configuration file

<package name= "B" namespace= "/" extends= "Struts-default" >
        <result-types>
                <result-type name= "JSON" class= "Org.apache.struts2.json.JSONResult"/>
        </result-types>
        <interceptors>
                <interceptor name= "JSON" class= "Org.apache.struts2.json.JSONInterceptor"/> <interceptor-stack name=
                " P1 ">
                        <interceptor-ref name=" Defaultstack "/> <interceptor-ref name=
                        " json "/>
                interceptor-stack>
        </interceptors>
        
        <action name= "Get_user" class= " Com.action.SyohinGetAction ">
                <result type=" json ">
                        <param name=" root ">list</param>
                </result>
        </action>
</package>
Where Result-type is referenced from the Struts2-json-plugin-2.3.20.jar.

<action name= "Get_user" class= "com.action.SyohinGetAction" >
                <result type= "json" >
                        <param Name= "root" >list</param>
                </result>
</action>
This action turns the list directly into JSON data. (List in the background is java.util.List)

The Get_user action display is automatically adjusted when the JSP page is initialized.

The order of the JSON data can be different from the foreground, but the project must be consistent.


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.