定义拦截器栈之前,必须先定义组成拦截器栈的多个拦截器。struts2把拦截器栈当成拦截器处理。
因此拦截器和拦截器栈都放在<interceptors.../>元素中定义。
例如:
<interceptors>
<!-- 定义权限检查的拦截器 -->
<interceptor name="authority" class="cn.edu.zust.AuthorityInterceptor" />
<!-- 定义日志记录的拦截器 -->
<interceptor name="log" class="cn.edu.zust.LogInterceptor" />
<!-- 定义拦截器栈 -->
<interceptor-stack name="authorityandlog" >
<!-- 定义该拦截器栈里包含authority拦截器 -->
<interceptor-ref name="authority" />
<!-- 定义该拦截器栈里包含log拦截器 -->
<interceptor-ref name="log" />
</interceptor-stack>
</interceptors>
定义拦截器栈之前,必须先定义组成拦截器栈的多个拦截器。struts2把拦截器栈当成拦截器处理。
因此拦截器和拦截器栈都放在<interceptors.../>元素中定义。
例如:
<interceptors>
<!-- 定义权限检查的拦截器 -->
<interceptor name="authority" class="cn.edu.zust.AuthorityInterceptor" />
<!-- 定义日志记录的拦截器 -->
<interceptor name="log" class="cn.edu.zust.LogInterceptor" />
<!-- 定义拦截器栈 -->
<interceptor-stack name="authorityandlog" >
<!-- 定义该拦截器栈里包含authority拦截器 -->
<interceptor-ref name="authority" />
<!-- 定义该拦截器栈里包含log拦截器 -->
<interceptor-ref name="log" />
</interceptor-stack>
</interceptors>
------------------------------------------------------------------------------------------
使用拦截器:
在上面我们定义了两个拦截器,并将两个拦截器组成了一个拦截器栈。一旦定义了拦截器和拦截器栈
之后,在Action中使用拦截器和拦截器栈的方法是相同的。
例如:
<action name="myAction" class="cn.edu.zust.myAction">
<result name="success">login.jsp</result>
<!-- 调用自定义拦截器栈 -->
<interceptor-ref name="authorityandlog" />
</action>
注意:对于Action而言,引用拦截器和拦截器栈的用法是完全一样的。
定义拦截器栈之前,必须先定义组成拦截器栈的多个拦截器。struts2把拦截器栈当成拦截器处理。
因此拦截器和拦截器栈都放在<interceptors.../>元素中定义。
例如:
<interceptors>
<!-- 定义权限检查的拦截器 -->
<interceptor name="authority" class="cn.edu.zust.AuthorityInterceptor" />
<!-- 定义日志记录的拦截器 -->
<interceptor name="log" class="cn.edu.zust.LogInterceptor" />
<!-- 定义拦截器栈 -->
<interceptor-stack name="authorityandlog" >
<!-- 定义该拦截器栈里包含authority拦截器 -->
<interceptor-ref name="authority" />
<!-- 定义该拦截器栈里包含log拦截器 -->
<interceptor-ref name="log" />
</interceptor-stack>
</interceptors>