[Struts2]13-方法拦截器

前面说的拦截器,是拦截整个Action的,但是如我们只想拦截Action中的某个方法,那么就需要使用方法拦截器。使用方法拦截器需要继承MethodFilterInterceptor类。代码如下

public class asd extends MethodFilterInterceptor {  
    @Override  
    protected String doIntercept(ActionInvocation actionInvocation) throws Exception {  
        return null;  
    }  
}  

struts.xml配置文件中配置方法拦截器

  
  
          
              
                list  
              
          
          
          
              
          
   
  

有两个参数,一个设置被拦截方法(includeMethods),另一个设置不被拦截方法(excludeMethods),多个方法是用逗号分隔。

注意:在配置action元素的时候一定要使用method属性,因为它是通过这个属性进行拦截的。

你可能感兴趣的:([Struts2]13-方法拦截器)