慕无忌5903725
2017-10-06 20:15
警告: Could not find action or result: /HelloWorld/helloworld_add.action
There is no Action mapped for namespace [/] and action name [helloworld_add] associated with context path [/HelloWorld]. - [unknown location]
public class HelloWorldAction extends ActionSupport {
public String add() {
System.out.println("执行add");
return "add";
}
public String update() {
return "update";
}
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="helloworld_*" method="{1}" class="com.imooc.action.HelloWorldAction">
<result>/index.jsp</result>
<result name="add">/{1}.jsp</result>
<result name="update">/{1}.jsp</result>
</action>
</package>
<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
</struts>
<struts> <package name="default" namespace="/" extends="struts-default" strict-method-invocation="false"> <action name="*_*" method="{2}" class="com.cailiang.action.{1}Action"> <result>/result.jsp</result> <result name="add">/{2}.jsp</result> <result name="update">/{2}.jsp</result> <allowed-methods>add,update</allowed-methods> </action> </package> <constant name="struts.enable.DynamicMethodInvocation" value="false"></constant> </struts>
添加allowed-method, 参考 https://www.jianshu.com/p/b6c961a1a141
struts2版本的问题吧 是不是要添加allow-methods
看看你的报错,namespace的问题。
就是照你所说的写得代码啊,可是还是显示404错误啊
肯定不对啊,action name="helloworld_*" method="{1}" 表示你响应的只能是helloworld_*.action的动作,比如说响应helloworld_login.action,而method{N}代表前面的第N个*匹配子串,意思是跳转到login.jsp页面。看看你有写了这些相应的action没,以及jsp页面有与之对应的没
Struts2入门
95061 学习 · 456 问题
相似问题