Struts2 给action配置一个局部拦截器后,action属性无法获得表单参数
今天碰到一个很郁闷的问题,搞了好久,如题,
原因还是不熟悉struts2的内部运作机制,
分析:
给acton配置一个自定义拦截器后,此action就无法使用框架默认提个的拦截器栈了,这就导致了前后台数据传输这个问题,实际上框架提个的所有拦截器都无法使用了,
解决方法:
在配置自定义拦截器之前,要记得把框架提个的拦截器栈先配置一下,然后就一切正常了,样例配置如下:
<action name="cn.individualChangeAction" name="code"><action name="login_*" method="{1}" > <result name="success">/getall.jsp</result> <result name="input">/index.jsp</result> <result name="login">/login.jsp</result> <interceptor-ref name="Authority"> <param name="includeMethods">getall</param> </interceptor-ref> </action>
我这么写还是获取不到表单的信息,我在set方法里面加了个打印信息,居然不调用那个set方法。
<action name="login_login" method="login" > <result name="input">/index.jsp</result> <result name="login">/login.jsp</result> <interceptor-ref name="Authority"> <param name="includeMethods">getall</param> </interceptor-ref> </action><action name="login_*" method="{1}" > <result name="success">/getall.jsp</result> <result name="input">/index.jsp</result> <result name="login">/login.jsp</result> <interceptor-ref name="Authority"> <param name="includeMethods">getall</param> </interceptor-ref> </action>