首先创建一个拦截器类:
public class CustomInterceptor implements Interceptor {
private static final long serialVersionUID = 1L;
public void destroy() {
}
public void init() {
}
public String intercept(ActionInvocation invocation) throws Exception {
if (invocation.getAction() instanceof BaseAction) {
system.out.println("进入拦截器");
return invocation.invoke();
} else {
return invocation.invoke();
}
}
}
然后配置struts.xml文件:
<package name="default" extends="struts-default">
<interceptors>
<interceptor name="customInterceptor"
class="com.test.utils.CustomInterceptor"></interceptor>
</interceptors>
</package>
这样就完成了拦截器的配置