Struts2的初学者遇到的一些问题。
今天在使用Struts2的时候,新学到了DMI的功能。
于是在JSP中,将表单提交到了名为login 的Action 中的 login方法
于是乎跑的时候,发现会报错,提示There is no Action mapped for namespace[/] and action name[login!login] associated with context path[/Login_Register]
通过官网查询 http://struts.apache.org/docs/action-configuration.html,发现原来使用DMI前,要在struts.xml中进行设置,添加这两句
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<constant name="struts.devMode" value="false"></constant>
再跑的时候,发现又出现了一个新的错
Method login for login is not allowed!
通过网上查询,发现要设置一个<global-allowed-methods>的标签,把自己的方法加在其中
<global-allowed-methods>login</global-allowed-methods>
但是添加这个标签之后,struts.xml就报错。报错的意思大概就是无法识别该标签。
后面自己不断的查询资料,发现这个标签是在struts2.5之后才出现的。而我的struts.xml中的头由于一开始打的时候偷懒,Struts2的版本就只打成了2.0
后来将struts-2.0 以及上面的2.0 修改成2.5(即我正在使用的版本)
一切就都解决了!
很简单的一个小问题,浪费了我一天的时间才解决,看来在处理版本号的时候要更小心