Ajax implementation based on struts2Action

We all send ajax requests to the servlet. The servlet can directly send some data back to html or jsp by obtaining the PrintWriter through the Response. Then, based on the action, it is not impossible to send back the data directly, or the ServletResponseAware interface can only be implemented in the Action to be like a servlet. to post back via PrintWriter? In fact, we only need to configure it in struts.xml.

<result name="success" type="json">

			
<!-- This indicates that the parameter with the value of null is excluded, and includeProperties is not configured, so those getter methods with value should be removed, otherwise the error of java.sql.SQLException: Positioned Update not supported. will be generated, the reason It's a matter of lazy loading -->
	<param name="excludeNullProperties">true</param>

</result>

 Of course, you can also specify the returned parameters as below, but in this case, you must specify the getter method of the parameter. The parameter I will pass here is an array. When returning, pay attention to it, you must add .* or return can't go back

<action name="mainAction" class="org.mysolesys.main.MainAction"
			method="getImagePath">
			
	<result name="success" type="json">
		<param name="includeProperties">pathsMap.*</param>
	</result>
	<result name="login">/login/user_login.html</result>
</action>

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326667611&siteId=291194637