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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qwl755/article/details/83899480

在我们使用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>

 

猜你喜欢

转载自blog.csdn.net/qwl755/article/details/83899480