通过对struts2的学习,对于interceptor中的excludeMethods与includeMethods的理解:
针对MethodFilterInterceptor:
excludeMethods表示排除指定的方法,即不对标记为excludeMethods的方法进行拦截,【拦截是说在Action的基础上执行拦截器里面的逻辑】
includeMethods表示包含指定的方法,即对标记为includeMethods的方法进行拦截, 【不拦截是说在Action的基础上不执行拦截器里面的逻辑代码】
在struts.xml中关于excludeMethods和includeMethods有两种实现方式,一种相当于全局,另一种相当于局部,即<interceptors>
<interceptor name="method"class="com.yxl.interceptor.MethodInterceptor">
<paramname="includeMethods">method1,method2</param>
</interceptor>
</interceptors>为全局
而 <interceptor-refname="method">
<paramname="excludeMethods">method1,method2</param>
</interceptor-ref>
为局部,若全局中的param定义为excludeMethods同样局部中的param也定义为excludeMethods,则局部中的param生效,全局中的param无效,即被局部中的param覆盖,同样,若全局中的param定义为includeMethods同样局部中的param也定义为includeMethods,则局部中的param生效,全局中的param无效,即被局部中的param覆盖。
当全局中的param与局部中的param不相同的时,即当全局中param为excludeMethods而局部中的param为includeMethods和全局中的param为includeMethods而局部中param为excludeMethods,则标志为includeMethods生效,即若是全局中的param定义为includeMethods,则全局屏蔽局部,以全局为准,反之,以局部为准。
尤其值得注意的是,自定义的拦截器类一定要继承MethodFilterInterceptor
struts2MethodFilterInterceptor类,该类是AbstractInerceptor的子类,可以实现对Action方法的拦截.实现MethodFilterInterceptor才能使用方法拦截
MethodFilterInterceptor中有两个方法
setExcludeMethods:排除需要过滤的方法
setIncludeMethods:设置需要过滤的方法
如果一个方法同时在excludeMethods和includeMethods中出现,则会被拦截
struts2中关于拦截器Interceptor中的excludeMethods和includeMethods的理解
猜你喜欢
转载自blog.csdn.net/qq_38869854/article/details/81198221
今日推荐
周排行