需要引入org.apache.
struts2.convention.annotation.InterceptorRefs,配合@InterceptorRef使用,通过它定义一些拦截器。参考样例如下:
class="java">UserAction.java [color=red]方式一,定义在方法上面[/color]
public class UserAction extends BaseAction <User> {
......
@Action(value = "testInter",
results = @Result(name =INTERCEPTOR_ERROR, location = "inter-error..action?id=${id}"),
interceptorRefs = @InterceptorRef("parmsUrl")
)
public String testInter(){
......
}
UserAction.java [color=red]方式二,定义在类上面[/color]
@Results( { ......,
@Result(name = UserAction.INTERCEPTOR_ERROR, location = "inter-error.action?id=${id}", type = "redirect")
})
@InterceptorRefs( {@InterceptorRef("defaultStack"),@InterceptorRef(value="parmsUrl",params={"includeMethods","testInter"})})
public class UserAction extends BaseAction <User> {
......
public String testInter(){
......
}
ParamUrlInterceptor.java
public class ParamUrlInterceptor implements Interceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {
业务逻辑,实现拦截......
}
......
struts.xml
<interceptors>
......
<!-- 自定义拦截器 -->
<interceptor name="parmsUrl" class="cn.eavic.example.security.interceptor.ParamUrlInterceptor">
</interceptor>
</interceptors>