struts 中default-action-ref的问题

本文探讨了Struts框架中default-action-ref配置项的实际应用效果与预期不符的问题。通过具体示例,展示了当请求的Action未定义时,并未能映射到预设的默认Action。文章进一步分析了可能的原因,并提出了两种解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近使用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 修改通配符的设置



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值