0

我在我的 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>

其中 my1-i 和 my2-i 是我的自定义拦截器。我不使用这个拦截器

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

但是,我的操作是 Preparable、ModelDriven 和 Validateable 工作得很好......为什么?

追问:我省略了一个重要细节:拦截器栈定义在第一个包中,被所有子包继承。

更准确地说,我想问这个:为什么如果我的操作实现了 Preparable<interceptor-ref name="prepare"/> ,并且我的自定义堆栈中没有拦截器 ' ',那么prepare方法会被正确调用吗?

4

2 回答 2

1

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).

于 2010-10-21T20:44:15.997 回答
0

这些包含在 paramsPrepareParamsStack 中。下面是根据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>
于 2015-07-29T23:02:05.447 回答