struts选择拦截某些方法

public abstract class MethodFilterInterceptor extends AbstractInterceptor {  
    protected transient Logger log = LoggerFactory.getLogger(getClass());  
      
    protected Set<String> excludeMethods = Collections.emptySet();  
    protected Set<String> includeMethods = Collections.emptySet();  
 
    public void setExcludeMethods(String excludeMethods) {  
        this.excludeMethods = TextParseUtil.commaDelimitedStringToSet(excludeMethods);  
    }  
      
    public Set<String> getExcludeMethodsSet() {  
        return excludeMethods;  
    }  
 
    public void setIncludeMethods(String includeMethods) {  
        this.includeMethods = TextParseUtil.commaDelimitedStringToSet(includeMethods);  
    }  
      
    public Set<String> getIncludeMethodsSet() {  
        return includeMethods;  
    }  
 
    @Override 
    public String intercept(ActionInvocation invocation) throws Exception {  
        if (applyInterceptor(invocation)) {  
            return doIntercept(invocation);  
        }   
        return invocation.invoke();  
    }  
 
    protected boolean applyInterceptor(ActionInvocation invocation) {  
        String method = invocation.getProxy().getMethod();  
        // ValidationInterceptor  
        boolean applyMethod = MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, method);  
        if (log.isDebugEnabled()) {  
            if (!applyMethod) {  
                log.debug("Skipping Interceptor... Method [" + method + "] found in exclude list.");  
            }  
        }  
        return applyMethod;  
    }  
      
    /**  
     * Subclasses must override to implement the interceptor logic.  
     *   
     * @param invocation the action invocation  
     * @return the result of invocation  
     * @throws Exception  
     */ 
    protected abstract String doIntercept(ActionInvocation invocation) throws Exception;  
      
}  


<!--使用拦截器-->
            <interceptor-ref name="defaultStack"></interceptor-ref> 
            <interceptor-ref name="FilterInterceptor"> 
<!--拦截器黑白名单-->
                 <param name="includeMethods">method1</param> 拦截
                 <param name="excludeMethods">method2</param> 不拦截
<!--指定参数name的值-->
<param name="name">FilterMethod</param>
            </interceptor-ref> 

你可能感兴趣的:(struts)