In an SSH project, sometimes it is necessary to jump from one action to another action. There are two ways to realize jump between Actions, one is chain and the other is redirectAction. The difference between these two ways is that chain is jumping on the server, which can realize data sharing between different Actions; while redirectAction is jumping on 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 parameter values
In the struts.xml file, define the first call Action:
<action name="XXX"> <result name="success"></result> <result name="input" type="chain"> <param name="actionName">input_error</param> </result> </action>
Define the second action to be called:
<action name="input_error"> <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 error_status and error_desc values in the first Action are passed to the status and desc of the second Action respectively, thus realizing the passing of parameter values. It is important to note that the variables that pass parameter values must have getter() and setter() methods, otherwise the value passed in the past is null.
The above is the use of alias interceptor in JavaWeb development that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!