日期:2014-05-17  浏览次数:20736 次

初学者问题,关于拦截器的param参数的作用。
XML code
<package name="struts2tutoial" extends="struts-default">
        <interceptors>
            <interceptor name="MyInterceptor" class="interceptor.MyInterceptor"/>
            <interceptor name="FilterInterceptor" class="interceptor.FilterInterceptor"/>
        </interceptors>
        <action name="HelloWorld" class="helloWorld">
            <result>/helloWorld.jsp</result>
            <interceptor-ref name="defaultStack"/>
            <interceptor-ref name="MyInterceptor"/>
            <interceptor-ref name="FilterInterceptor">
                <param name="includeMethods">a,b</param>
                <param name="excludeMethods">e,f</param>
            </interceptor-ref>
        </action>
    </package>


上面代码中:

<param name="includeMethods">a,b</param>
<param name="excludeMethods">e,f</param>

有什么作用呢?我看到的解释是“分别代表指定拦截器拒绝拦截的方法和需要拦截的方法”,但是在不理解是什么意思。

------解决方案--------------------
同样在学struts2 不是怎么理解 帮你顶下哈
------解决方案--------------------
就是调用相应的方法时使用拦截器,以前看过一点这方面的书
------解决方案--------------------
a,b,e,f

都是你项目业务Action中对应的方法名。

比如:

FilterInterceptor拦截器是往数据库写操作log用的。

执行a和b方法的时候,能写log.
执行e和f方法的时候,不能写log.