简体   繁体   English

struts2拦截器堆栈

[英]struts2 interceptor stack

I write in my struts.xml this interceptor stack 我在struts.xml中编写了这个拦截器堆栈

<interceptor-stack name="project-interceptors-stack">                                               
    <interceptor-ref name="my1-i" />
    <interceptor-ref name="my2-i" />                
    <interceptor-ref name="paramsPrepareParamsStack" /> 
    <interceptor-ref name="logger" />
    <interceptor-ref name="timer" />
</interceptor-stack>

where my1-i and my2-i are my custom interceptor. 其中my1-i和my2-i是我的自定义拦截器。 I do not use this interceptor 我不使用这个拦截器

<interceptor-ref name="i18n"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="validation">

but, my action's, which are Preparable, ModelDriven and Validateable work well ... why ? 但是,我的动作(可准备,模型驱动和可验证)可以很好地工作...为什么?

Follow-up: I omitted an important detail: the interceptor stack is defined in the first package and is inherited by all sub package. 后续:我省略了一个重要的细节:拦截器堆栈在第一个包中定义,并被所有子包继承。

More precisely i wanted to ask this: why if my action implements Preparable , and i don't have the interceptor ' <interceptor-ref name="prepare"/> ' in my custom stack, the prepare method is called correctly? 更确切地说,我想问一个问题:为什么我的动作实现了Preparable ,而我的自定义堆栈中没有拦截器' <interceptor-ref name="prepare"/> ,则prepare方法被正确调用了吗?

What do you precisely mean with this? 你这到底是什么意思?

my actions, which are Preparable, ModelDriven and Validateable work well 我的操作(可准备,模型驱动和可验证)运行良好

You mean that the interceptors appear to be applied, for example, declarative validation is applied? 您的意思是拦截器似乎已被应用,例如,是否应用了声明式验证? (You can check what each standard interceptor is supposed to do here ) (您可以在此处检查每个标准拦截器应该做什么)

If so, you should check that your stack is effectively used in you action, by specifying it in the action mapping or globally (the code you posted simply defines a stack). 如果是这样,则应通过在操作映射或全局映射中指定堆栈来检查堆栈是否在操作中有效使用(发布的代码仅定义了堆栈)。

These are included in the paramsPrepareParamsStack. 这些都包含在paramsPrepareParamsStack中。 Below is the definition according to struts-default.xml, 下面是根据struts-default.xml的定义,

<interceptor-stack name="paramsPrepareParamsStack">
            <interceptor-ref name="exception"/>
            <interceptor-ref name="alias"/>
            <interceptor-ref name="i18n"/>
            <interceptor-ref name="checkbox"/>
            <interceptor-ref name="datetime"/>
            <interceptor-ref name="multiselect"/>
            <interceptor-ref name="params"/>
            <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"/>
            <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM