Use of the alias interceptor and the alias interceptor

Source: Internet
Author: User

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.

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.