编写类,实现Interceptor接口。
<package name="inter" extends="struts-default" namespace="/inter">
<interceptors>
<interceptor name="inter1" class="gz.itcast.a_interceptor.MyInterceptor1"></interceptor>
</interceptors>
<action name="user_*" class="gz.itcast.a_interceptor.UserAction" method="{1}">
<interceptor-ref name="inter1"></interceptor-ref>
<result>/index.jsp</result>
</action>
</package>
<package name="inter" extends="struts-default" namespace="/inter">
<interceptors>
<interceptor name="inter1" class="gz.itcast.a_interceptor.MyInterceptor1">
</interceptor>
</interceptors>
<default-interceptor-ref name="inter1"></default-interceptor-ref> 覆盖了struts-default内的拦截器
...............
</package>
<interceptors>
<interceptor name="inter1" class="gz.itcast.a_interceptor.MyInterceptor1"></interceptor>
<interceptor name="inter2" class="gz.itcast.a_interceptor.MyInterceptor2"></interceptor>
<interceptor-stack name="interStack">
<interceptor-ref name="inter1"></interceptor-ref>
<interceptor-ref name="inter2"></interceptor-ref>
</interceptor-stack>
</interceptors>
<interceptor-stack name="myStack">
<interceptor-ref name="defaultStack"></interceptor-ref><!-- 引入了默认的18个拦截器 -->
<interceptor-ref name="interStack"></interceptor-ref><!-- 引入自定义的2个拦截器 -->
</interceptor-stack>