Struts2中自定义拦截器导致Action注入参数丢失

来源:互联网 发布:仿真软件matlab 编辑:程序博客网 时间:2024/06/04 17:52

写struts2项目时发现前台超链接中的参数无法传到action,

所有带有传递参数的均无法正常使用了,在Action中所有的参数无法被注入。
后来经过debug发现其中的页面都要先经过拦截器,而后再经过action,心想是不是拦截器将参数拦截下来,

最后发现,struts-default中,默认的拦截器引用是defaultstack,这个拦截器包传说是经过精心设计的。。所以会把所有的参数注入!
因此要更改默认拦截器,需要加上这个defaultstack
只有加上这个默认的拦截器才不会将参数拦截
<package name="users-authority" extends="struts-default"><!-- 受权限控制的Action配置 -->
<interceptors>
<interceptor name="authority" class="com.huizhi.util.interceptor.AuthorityInterceptor"/><!-- 定义包含权限检查的拦截器 -->
<interceptor-stack name="mydefault"><!-- 配置内建默认拦截器 -->
<interceptor-ref name="authority"/>
<interceptor-ref name="defaultStack"/><!-- 配置自定义的拦截器 -->

</interceptor-stack>

</interceptors>

<action name="selectinfo" class="com.huizhi.users.action.SelectInfoAction" method="selectInfo"><!-- 查看用户个人信息 -->
<result name="success">/selectinfo.jsp</result>
<result name="input">/showInfo.jsp</result>
<result name="find">/admin/selectInfo.jsp</result>
</action>

</package>
特别注意红色两行的顺序!先自定义再Default

0 0