1.struts2的拦截器:
拦截器分为自定义拦截器和struts2默认的拦截器
自定义拦截器的action:
1.继承 AbstractInterceptor
2.重写 intercept方法
3.在intercept方法中进行拦截操作
struts2默认的拦截器,直接引用
struts2的配置文件中如何引入拦截器
1.注册拦截器
<interceptors>
<!-- 单个拦截器-->
<interceptor name="myExceptionInterceptor" class="com.hq.tools.MyExceptionInterceptor"> </interceptor> <!-- 拦截器栈 --> <interceptor-stack name="myStack"> <interceptor-ref name="myExceptionInterceptor"></interceptor-ref><!--引入默认的拦截器栈-->
<interceptor-ref name="defaultStack"></interceptor-ref> </interceptor-stack></interceptors>
2.使用拦截器
<default-interceptor-ref name="myStack"></default-interceptor-ref>
3.该包下面的action在执行之前都进过这些拦截器