现在的位置: 首页 > 综合 > 正文

struts2拦截器的问题

2018年02月12日 ⁄ 综合 ⁄ 共 616字 ⁄ 字号 评论关闭
顺便向大家提个醒,使用自定义的Interceptor时,一定要定义一个Interceptor栈,定义你自己的拦截器和系统默认拦截器的调用顺序,如果直接在action中引用你自定义的拦截器,就会发现只调用了你自己的拦截器,没有调用Struts2中内置的拦截器,那样有很多功能就会运行不正常了。

<interceptors>
<interceptor name="authorize" class="com.struts2.interceptor.AuthorizeInterceptor" />
<interceptor-stack name="appStack">
<!-- 你自定义的 -->
<interceptor-ref name="authorize"/>
<!-- 系统内置的拦截器栈 -->
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<action name="forward" class="com.struts2.RequestForward">
<interceptor-ref name="appStack"/>
<result name="index">index.jsp</result>
<result name="NOT_FOUND">not_found.jsp</result>
</action>

抱歉!评论已关闭.