struts2 <action>无法使用通配符解决办法

本文探讨了在Struts2框架中使用通配符配置action的方法,特别关注于解决因版本不同导致的运行错误。文章指出,在Struts2.3及更高版本中,为使通配符配置生效,需在action标签内加入&lt;allowed-methods&gt;子标签,明确指定允许的方法。

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

在我们使用struts2的时候,肯定不想每一个方法就写一<action>,所以通常我们会使用通配符,简化我们的代码。

 <action name="userAction_*" class="userAction" method="{1}" >
            <result name="login">/login.jsp</result>
            <result name="home">/index.jsp</result>
        </action>

但自己发现运行的时候,前端会报错,说找不到action

Struts Problem Report 
Struts has detected an unhandled exception:

Messages: There is no Action mapped for namespace [/] and action nam [userAction_login] associated with context path [/bos-web].

       但在网上找,发现是因为版本的问题,因为我使用的是struts2 2.5,搜索后发现在struts2.3版本之后需要在action标签加上这行代码<allowed-methods>方法1,方法2…</allowed-methods>才能使用通配符。

  <action name="userAction_*" class="userAction" method="{1}" >
            <result name="login">/login.jsp</result>
            <result name="home">/index.jsp</result>
            <allowed-methods>login</allowed-methods>
        </action>

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值