最近两天刚接触Struts2.0,没有什么现成的教科书,只是根据官网的一些说明文档来学习。过程中遇到了许多莫名其妙的问题,解决的方法也更是莫名其妙。
首先是通配符的问题:
最开始的Struts配置文件如下:
<struts>
<package name="org.emarket.begin" namespace="/begin" extends="struts-default">
<action name="helloworld" class="org.emarket.begin.HelloWorld">
<result>/begin/helloworld.jsp</result>
</action>
<action name="*">
<result>/begin/{1}.jsp</result>
</action>
<action name="login!*" method="{1}" class="org.emarket.begin.Login">
<result name="input">/begin/login.jsp</result>
<result type="redirect-action">test</result>
</action>
</package>
</struts>编写了一个form表单,其action属性设为login,表单使用了Validator验证,可是不管怎样输入表单栏位,提交后的结果总是跳转 到/begin/login.jsp页面,而不是SUCESS页面。开始觉得很奇怪,为什么login!*通配符不起作用。
将配置文件更改为:
<struts>
<package name="org.emarket.begin" namespace="/begin" extends="struts-default">
<action name="helloworld" class="org.emarket.begin.HelloWorld">
<result>/begin/helloworld.jsp</result>
</action>
<action name="login!*" method="{1}" class="org.emarket.begin.Login">
<result name="input">/begin/login.jsp</result>
<result type="redirect-action">test</result>
</action><!-- 顺序置换 -->
<action name="*">
<result>/begin/{1}.jsp</result>
</action>
</package>
</struts>我知道这种问题对于老鸟们不屑一顾,可对于Struts2.0刚起步的菜鸟来讲,让我由实感到“莫名其妙”。
本文探讨了Struts2框架中通配符配置导致的问题及解决方案,通过调整配置文件中action的顺序解决了表单提交后无法正确转向的问题。
636





