最近小弟我看中struts2中类似ruby on rails 的uri友好性的特点(比如http://www.iteye.com/topic/199074,而不是:http://www.iteye.com/topic.do?topicid=199074)准备试试。
按照starting-struts2.pdf中的描述:在struts.xml中做如下配置:
[code="java"]
<!--主要就是这个-->
value="org.apache.struts2.dispatcher.mapper.Restful2ActionMapper" />
<package name="web" namespace="/" extends="struts-default">
<action name="register" class="com.test.user.RegisterAction">
<result name="index">/user/index.jsp</result>
<result name="success">/user/user.jsp</result>
</action>
</package>
[/code]
类com.test.user.RegisterAction中不执行任何逻辑代码,只是返回字符串。
根据starting-struts2.pdf中的说明,当用GET:/register/时,应该调用com.test.user.RegisterAction中的index方法。可实际运行时却是:当RegisterAction中有execute方法时只执行execute方法;去掉execute方法时任何方法都不调用。
各位达人看看能不能帮忙指点一二。
[b]问题补充:[/b]
昨天把struts2的tutorial再看了一遍,发现还要在web.xml的dispathFilter里增加一个参数:resourcePackages,并把需要区别于一般action的类命令为*Resource.
多谢kyo100900了,多谢支持,就采纳为最佳答案了:)