您的位置:首页 > 编程语言 > Java开发

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

2015-01-21 16:45 423 查看
写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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: