struts2中使用自定拦截器
struts2中实现自定义的拦截器,有三种方式:
??? 1、实现interceptor接口
??? 2、继承AbstractInterceptor这个抽象类
??? 3、继承MethodFilterInteceptor类
?
这里我只用了第一种方式:
?
<interceptors > <interceptor name="InterceptorOne" name="code">import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; public class MyInterceptorOne implements Interceptor{ public void destroy() { // TODO Auto-generated method stub } public void init() { // TODO Auto-generated method stub } public String intercept(ActionInvocation invocation) throws Exception { // TODO Auto-generated method stub System.out.println("begin to intercept..."); String result = invocation.invoke(); System.out.println("end to intercept..."); return result; } } ?
?
?在配置文件中配置: