Struts2 interceptor defastack stack and paramsprepareparamsstack

Source: Internet
Author: User
Tags i18n

The struts-default.xml defines a series of interceptor and interceptor chains

A default interceptor defastack stack is also defined. Once the default interceptor is defined,

This interceptor will take effect for all the actions in the package. Of course, if your Action explicitly defines the interceptor,

By default, the interceptor will lose its role. If you want to prevent it from being ineffective,

You must also explicitly define the system's default interceptor.

       </interceptors>

<default-interceptor-ref name="defaultStack"/>

<default-class-ref class="com.opensymphony.xwork2.ActionSupport" />
</package>

The "defaultstack" and "paramsprepareparamsstack" Interceptor stacks provide most of the interceptor functions.

The interception sequence is different. The former is usually used, but some problems related to parameter transfer and Value

For example, when the modeldriven interface is implemented, you do not need to write the interceptor class by yourself.

defaultStack
            <interceptor-stack name="defaultStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="debugging"/>
<interceptor-ref name="scopedModelDriven"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="multiselect"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
</interceptor-ref>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
paramsPrepareParamsStack
            <interceptor-stack name="paramsPrepareParamsStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="multiselect"/>
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
</interceptor-ref>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
</interceptor-ref>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>

Defaultstack cannot receive the data required by prepare (), but should use paramsprepareparamsstack interceptor Stack

Before using the prepare interceptor, call the Params Interceptor to receive the form data.

Based on this idea, you can place the Params interceptor before the prepare interceptor by various means.

For example, copy all the interceptors in defaultstack to the custom mystack interceptor stack in struts. xml.

Modify the positions of the two parts in the order of Params and prepare in the paramsprepareparamsstack interceptor stack.

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.