最近使用struts 时, 发现配置struts 时产生的一个问题。使用default-action-ref 并不能达到所属的相应效果。
按照struts文档所说, default-action-ref 的作用:
Usually, if an action is requested, and the framework can't map the request to an action name, the result will be the usual "404 - Page not found" error. But, if you would prefer that an omnibus action handle any unmatched requests, you can specify a default action. If no other action matches, the default action is used instead.
但是真的不是这样。。。
以下是我的struts.xml相应配置:
<package name="admin" namespace="/admin" extends="struts-default">
<default-action-ref name="index"></default-action-ref>
<action name="index">
<result>/admin/index.html</result>
</action>
<action name="*_*" class="com.joey.bbs3s.action.{1}Action"
method="{2}">
<result>/admin/{1}_{2}.jsp</result>
<result name="input">/admin/{1}_{2}.jsp</result>
<exception-mapping result="error" exception="java.sql.SQLException">
</exception-mapping>
<result name="error">/error.jsp</result>
</action>
</package>
想法很简单, 就是当/admin下面没有和 输入相匹配的action时,帮我映射到/admin/index 这个action。
实验结果:
(首先/admin/index 正常)
(没有action 可以匹配/admin/aaaaaaaa)
根据错误信息,推测可能与在package 中设置的通配符相关。
解决方案:
1. 在web.xml中设置(还未进行实验)
2.http://blog.sina.com.cn/s/blog_9772ef170101dczo.html 修改通配符的设置