struts配置文件就是上面贴出来的那些啊 ,就是那个使用onclick="location.href='login!query.action'" >的出错,那个提交按钮的能够通过项目名称就是struts2 HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2]. 你用的是DMI动态方法调用,在名为login的Action访问add()方法。 可是你在struts.xml定义的Action方法名为execute: <action name="login" class="Test.LoginAction" method="execute"> 这就不对了,你要么把execute去掉,要么把method改成add。 你的result的name只是Action中return的出口,而不是你的入口,好好检查一下。
struts配置文件就是上面贴出来的那些啊 ,就是那个使用onclick="location.href='login!query.action'" >的出错,那个提交按钮的能够通过项目名称就是struts2 HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2]. 你用的是DMI动态方法调用,在名为login的Action访问add()方法。 可是你在struts.xml定义的Action方法名为execute: <action name="login" class="Test.LoginAction" method="execute"> 这就不对了,你要么把execute去掉,要么把method改成add。 你的result的name只是Action中return的出口,而不是你的入口,好好检查一下。把execute去掉这样是不行的,默认的方法也是execute()啊,不写的效果是一样的。还有把method改成add的话四个增删改查这四个button还是没有实现。 不过谢谢你的建议。
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2].
你用的是DMI动态方法调用,在名为login的Action访问add()方法。
可是你在struts.xml定义的Action方法名为execute:
<action name="login" class="Test.LoginAction" method="execute">
这就不对了,你要么把execute去掉,要么把method改成add。
你的result的name只是Action中return的出口,而不是你的入口,好好检查一下。
解决方法:<action name="login" class="Test.LoginAction" method="execute">把这个配置五个分别对应你的五个按钮。
楼上说的去掉method的方法我觉得不可行,有两个疑问一个是如果去掉有可能还是找不到,如果能找到那么都会走execute方法那么在具体的execute方法中需要判断是哪个按钮的请求(这个难度应该很大)。如果你有什么好的解决方案也可以回复我!
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2].
你用的是DMI动态方法调用,在名为login的Action访问add()方法。
可是你在struts.xml定义的Action方法名为execute:
<action name="login" class="Test.LoginAction" method="execute">
这就不对了,你要么把execute去掉,要么把method改成add。
你的result的name只是Action中return的出口,而不是你的入口,好好检查一下。把execute去掉这样是不行的,默认的方法也是execute()啊,不写的效果是一样的。还有把method改成add的话四个增删改查这四个button还是没有实现。 不过谢谢你的建议。
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!add] associated with context path [/Struts2].
你用的是DMI动态方法调用,在名为login的Action访问add()方法。
可是你在struts.xml定义的Action方法名为execute:
<action name="login" class="Test.LoginAction" method="execute">
这就不对了,你要么把execute去掉,要么把method改成add。
你的result的name只是Action中return的出口,而不是你的入口,好好检查一下。把execute去掉这样是不行的,默认的方法也是execute()啊,不写的效果是一样的。还有把method改成add的话四个增删改查这四个button还是没有实现。 不过谢谢你的建议。
其实以前只是在书上看过DMI,一直没有实践过,今天就利用你这个问题的机会写了一个小demo测试了一下:
1.jsp代码和你的一样: <body>
<span style="font-size: 100px;color: red;font-weight: bold;">Struts2 DMI Test</span><br/>
<form action="login.action">
<input type="text" name="username" ><br>
<input type="password" name="password" ><br>
<input type="submit" value="提交" ><br>
<input type="button" value="查询" onclick="location.href='testone!query.action'" >
<input type="button" value="添加" onclick="location.href='testone!add.action'" >
<input type="button" value="删除" onclick="location.href='testone!delete.action'" >
<input type="button" value="修改" onclick="location.href='testone!update.action'" >
</form>
</body>
2.struts.xml代码:<package name="my01" namespace="/" extends="struts-default">
<action name="testone" class="com.fit.action.TestAction" method="execute">
<result name="success">/result01.jsp</result>
</action>
</package>
3.Action代码:public class TestAction extends ActionSupport{
public String query(){
System.out.println("This is query method!");
return "success";
}
public String add(){
System.out.println("This is add method!");
return "success";
}
public String delete(){
System.out.println("This is delete method!");
return "success";
}
public String update(){
System.out.println("This is update method!");
return "success";
}
}
4.测试一切正常,上图:
2.加上namespace="/"。
3.检查一下你Action中的方法名是否正确。
4.确认你没有改项目的默认路径。
其它的确实再看不出来还有什么可能性报这个异常。
我没改。我只测试的是4个按钮没问题。我跑过了没发现问题。如果你也找不到问题的话。我把项目发给你你跑一下。如果成功了你再自习对比一下。
我没改。我只测试的是4个按钮没问题。我跑过了没发现问题。如果你也找不到问题的话。我把项目发给你你跑一下。如果成功了你再自习对比一下。
终于知道原因了,是struts版本的原因,要在配置文件中加入动态调用