1.创建拦截器处理类
(1)继承AbstranctInterceptor类
(2)重写intercept方法
2.配置struts.xml文件
1 <!-- 定义拦截器的集合 -->
2 <interceptors>
3 <!-- 定义拦截器 -->
4 <interceptor name="logInterceptor" class="cn.bing.interceptor.LogInterceptor"></interceptor>
5 <!-- 定义拦截器栈 -->
6 <interceptor-stack name="myStack">
7 <!-- 1. 引用默认的拦截器栈,让struts2默认的拦截器栈先执行,从而是实现Strtus2的常用功能正常使用 -->
8 <interceptor-ref name="defaultStack"></interceptor-ref>
9 <!-- 2. 引用自定义的拦截器-->
10 <interceptor-ref name="logInterceptor"></interceptor-ref>
11 </interceptor-stack>
12 </interceptors>
13 <!-- 调用自定义的拦截器栈 -->
14 <default-interceptor-ref name="myStack"></default-interceptor-ref>