Struts2出现HTTP Status 404 - There is no Action mapped for namespace / and action
我想通过action把参数从一个页面传到另一个页面上,但总是出现404错误,到底是怎么回事啊!我检查N遍配置文件了 都没有错,还请高手指点一下:
struts.xml://struts.xml是放在class目录下,还是放在src目录下呢?我放到了class目录下面
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml"/>
<package name="test" extends="struts-default">
<action name="hello" class="test.Hello">
<result>result.jsp</result>
</action>
</package>
</struts>
PostP.jsp //用于用户输入信息
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>To past paramter</title>
</head>
<body>
<h2>please input you name:</h2>
<form action="hello.action" method="post">
<input type="text" name="name"></input><br></br>"
<input type="submit" value="submit" align="right"/><input type="reset" value="reset"align="left"></form>
</body>
</html>
result.jsp://用于显示参数的页面
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>come to the result</title>
</head>
<body>
<h2>Hello to you!</h2>
${name}
</body>
</html>
Hello.action:
package test;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class Hello extends ActionSupport {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String execute(){
return "success";
}
}
请高手给予指导:我是在哪里出错了,为何会出现这种错误,迫切渴望得到答案
------解决方案--------------------
struts.xml放在src目录下
------解决方案--------------------
随便放在哪里,自己在web.xml里面配置下就好了。
我是习惯丢在src下面,打开快,class需要好几层
XML code
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:/applicationContext.xml,
classpath*:/applicationContext_*.xml
</param-value>
</context-param>
------解决方案--------------------
最终 你要 确保 struts.xml 在
WEB-INF\classes
这个文件的目录里面