拦截器(Interceptor)是 Struts 2 的核心组成部分。
- Struts2 很多功能都是构建在拦截器基础之上的,例如文件的上传和下载、国际化、数据类型转换和数据校验等等。
- Struts2 拦截器在访问某个 Action 方法之前或之后实施拦截 Struts2 拦截器是可插拔的, 拦截器是 AOP(面向切面编程) 的一种实现.
- 拦截器栈(Interceptor Stack): 将拦截器按一定的顺序联结成一条链. 在访问被拦截的方法时,
- Struts2 拦截器链中的拦截器就会按其之前定义的顺序被依次调用

下面说明了栈的调用次序:
1 <package name="default" extends="struts-default"> 2 <!--配置拦截器--> 3 <interceptors> 4 <interceptor name="FirstInterceptor" class="Interceptor.FirstInterceptor"> 5 <param name="value" >YEN</param> 6 </interceptor> 7 <interceptor name="SecondInterceptor" class="Interceptor.SecondInterceptor"></interceptor> 8 //次序为 FirstInterceptor==》SecondInterceptor===》defaultStack===》SecondInterceptor====》FirstInterceptor
9 <interceptor-stack name="AllInterceptor">10 <interceptor-ref name="FirstInterceptor"></interceptor-ref>11 <interceptor-ref name="SecondInterceptor"></interceptor-ref>12 <interceptor-ref name="defaultStack"></interceptor-ref>13 </interceptor-stack

