HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!welcome] associ

2 篇文章 0 订阅
1 篇文章 0 订阅

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!welcome] associated with context path [/Struts-0908].(动态调用方法DMI失败)

我使用的struts版本为struts-2.3.24

struts.xml:

<pre name="code" class="html"><span style="font-size:24px;"><strong><struts>
    <package name="hello" extends="struts-default">
        <action name="hello" class="">
            <result>/index.jsp</result>
        </action>
        <action name="login" class="smu.edu.action.LoginAction">
            <result name="welcome">/welcome.jsp</result>
        </action>
        <action name="login2" class="smu.edu.action.LoginAction" method="login">
            <result name="login">/index.jsp</result>
        </action>
    </package>
</struts></strong></span>

 

action:

<span style="font-size:24px;"><strong>package smu.edu.action;

public class LoginAction {
	public String execute(){
		System.out.println("运行execute方法");
		return "success";
	}
	public String login(){
		System.out.println("运行login方法");
		return "login";
	}
	public String welcome(){
		System.out.println("运行welcome方法");
		return "welcome";
	}

}
</strong></span>


调用动态调用方法DMI,输入http://acer-pc:8080/Struts-0908/login!welcome,结果出现了



很多人都奇怪明明都没有敲错,都是按照步骤做的,怎么就不行了呢?因为struts2之前的版本动态方法DMI调用默认是打开的,一些struts版本可能动态调用方法DMI默认为关闭的。

解决方法:

<span style="font-size:24px;"><strong><struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
    <package name="hello" extends="struts-default">
        <action name="hello" class="">
            <result>/index.jsp</result>
        </action>
        <action name="login" class="smu.edu.action.LoginAction">
            <result name="welcome">/welcome.jsp</result>
        </action>
        <action name="login2" class="smu.edu.action.LoginAction" method="login">
            <result name="login">/index.jsp</result>
        </action>
    </package>
</struts></strong></span>

往struts.xml文件中添加如下:

<span style="font-size:24px;"><strong><constant name="struts.enable.DynamicMethodInvocation" value="true"></constant></strong></span>

结果成功:



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值