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
所有带有传递参数的均无法正常使用了,在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
相关文章推荐
- Struts2中自定义拦截器导致Action注入参数丢失
- Struts2使用自定义拦截器导致Action注入参数丢失、url参数
- struts2 在拦截器进行注入(根据Action是否实现自定义接口)
- Struts2 自定义拦截器时Action无法接收到参数
- 解决方法|struts2执行action前加入拦截器,导致获取不到参数
- Struts2 自定义拦截器时Action无法接收到参数
- Struts2 自定义拦截器栈后无法得到表单参数之解决办法
- Struts2之Action接收请求参数和拦截器详解
- 在Struts2拦截器中获取请求action名称及参数
- Struts2 二、为Action的参数注入值
- Struts2学习之2(请求参数的封装,类型转换,输入验证,自定义拦截器)
- 转--struts2自定义拦截器导致无法传参
- 自定义Struts2的拦截器&自定义UserAware接口&Action中模型赋值问题&Hibernate懒加载问题
- Struts2 自定义拦截器栈后无法得到表单参数之解决办法
- Struts2 二、为Action的参数注入值
- struts2中关于使用自定义的拦截器后,从页面提交过来的bean的参数的值为null的误区及解决
- Struts2之Action接收请求参数和拦截器
- Struts2 二、为Action的参数注入值
- Struts2 二、为Action的参数注入值
- Struts2Action请求转发以及参数 拦截器传递参数