1、首先继承 MethodFilterInterceptor
package com.lanou.test;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
public class MethodInterceptor extends MethodFilterInterceptor {
@Override
protected String doIntercept(ActionInvocation invok) throws Exception {
//只关心黑名单的过程,于是这里只执行过滤过程
return "login";
}
/*
* getIncludeMethodsSet() 黑名单 包含 里面的方法是要被拦截
* getExcludeMethodsSet() 白名单 不包含 里面的方法不拦截
*/
//不包含的通过,白名单
@Override
public Set<String> getExcludeMethodsSet() {
return super.getExcludeMethodsSet();
}
//黑名单,包含的不通过 默认include,优先级大
@Override
public Set<String> getIncludeMethodsSet() {
return super.getIncludeMethodsSet();
}
}
- import java.util.Set;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
public class MethodInterceptor extends MethodFilterInterceptor {
@Override
protected String doIntercept(ActionInvocation invok) throws Exception {
//只关心黑名单的过程,于是这里只执行过滤过程
return "login";
}
/*
* getIncludeMethodsSet() 黑名单 包含 里面的方法是要被拦截
* getExcludeMethodsSet() 白名单 不包含 里面的方法不拦截
*/
//不包含的通过,白名单
@Override
public Set<String> getExcludeMethodsSet() {
return super.getExcludeMethodsSet();
}
//黑名单,包含的不通过 默认include,优先级大
@Override
public Set<String> getIncludeMethodsSet() {
return super.getIncludeMethodsSet();
}
}
strust.xml的配置
拦截器中放的拦截器栈
<interceptor-stack name="methodallTest">
<interceptor-ref name="methodTest">
<!--设置拦截方法 ,白名单的 name="includeMethods"-->
<param name="excludeMethods">
//拦截的方法
login,register
</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>