Use of the alias interceptor and the alias interceptor
In an SSH project, sometimes one Action needs to jump to another Action. There are two ways to achieve jump between actions, one is chain and the other is redirectAction. The difference between the two methods is that chain is redirected on the server, data can be shared between different actions, while redirectAction redirects to the client.
Use chain to pass parameter values between different actions. This function can be implemented through the alias interceptor.
1. Specify the Filter class
Set the following interceptor in web. xml:
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
2. Pass the parameter value
In the struts. xml file, define the first called Action:
<action name="XXX" class="XXXAction"> <result name="success"></result> <result name="input" type="chain"> <param name="actionName">input_error</param> </result> </action>
Define the second called Action:
<action name="input_error" class="inputErrorAction"> <param name="aliases">#{'error_status':'status','error_desc':'desc'}</param> </action>
When the first Action returns input, it will jump to the second Action. At this time, the values of error_status and error_desc in the first Action will be passed to the status and desc of the second Action, respectively, thus, the parameter value is passed. You must note that the getter () and setter () methods must be used for passing parameter values. Otherwise, the passed value is null.