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

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

<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].

   但在网上找,你也会发现,很多都是这么写的,真的找了许久啊,我还记得上次也是这种错误,后来指定了method的方法名,也能实现。最后猜想会不会是因为版本的问题,因为我使用的是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>

还是因为自己经验不足啊,一直以为代码的问题,苦苦找了很久。自己写下来,记忆更加深刻一些。

作者:善亦有道
来源:CSDN
原文:https://blog.csdn.net/weixin_42933886/article/details/82258111

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值