struts2.1的拦截器给予AOP思想,采取可配置的方式控制,可做登录验证、权限、日志记录等
系统本身提供很多拦截器方便使用,但在实际中经常需要自定义拦截器
自定义拦截器可以实现interceptor接口,也可以继承abstractInterceptor类,重写intercept方法
struts.xml配置如下
<interceptors>
<interceptor name="auth" class="com.struts2.interceptor.AuthorInterceptor"></interceptor>
</interceptors>
定义一个自定义拦截器,class指具体实现interceptor接口或继承abstractinterceptor类
在需要用到的action中加入
<interceptor-ref name="auth"></interceptor-ref>