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.