Struts2中There is no Action mapped for namespace错误解决方法

时间:2023-03-09 19:07:21
Struts2中There is no Action mapped for namespace错误解决方法

1.我的原有配置

jsp表单提交路径

<form class="layui-form" id="form" action="${ctx }/membersLogin/membersLoginAction!membersLogin.action">
............
</form>

struts2拦截配置

    <package name="default" extends="struts-default" namespace="/membersLogin" strict-method-invocation="false">
<action name="membersLoginAction" class="seventykg.web.MembersLoginAction">
<result name="login_success">/index.jsp</result>
<result name="login_fail">/login_fail.jsp</result>
</action>
</package>

2.按常理来说是没问题的

但是每次提交表单的时候报错如下:

There is no Action mapped for namespace。。。。。。。。。

3.百度搜了一下各种解决方法,都不是我想要的,无奈自己看了一下struts.xml配置文件,发现有一个地方叫:

    <!-- 是否开启动态方法调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>

当这个value="false"的时候,是不支持(${ctx }/membersLogin/membersLoginAction!membersLogin.action)这样带有方法(membersLogin)的路径的,仅仅支持(${ctx }/membersLogin/membersLoginAction)这样的,方法的话需要写到配置文件中

<package name="default" extends="struts-default" namespace="/membersLogin" strict-method-invocation="false">
<action name="membersLoginAction" class="membersLoginAction" method="membersLogin">
<result name="login_success">/index.jsp</result>
<result name="login_fail">/login_fail.jsp</result>
</action>
</package>

改成true即可解决问题

=====================================================================================

今天特来补充一下还是这个异常问题:

在同一个struts配置文件中,package标签的name属性不能全为default,若有多个,必须给name起名字,若不然还是会报这个异常:

There is no Action mapped for namespace [/membersLogin] and action name [membersLoginAction] associated with context path...

QQ交流群4060038