type Status report
message /Struts2_HelloWorld/HelloWorld
description The requested resource (/Struts2_HelloWorld/HelloWorld) is not available.
***********************************************************************************************
开发环境:
JDK:jdk1.5.0_11
Tomcat:apache-tomcat-6.0.13
Eclipse Platform:Version: 3.3.0 Build id: I20070625-1500
Struts:struts-2.0.9
***********************************************************************************************
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Struts Blank</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
***********************************************************************************************
struts.xml
<!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="tutorial" extends="struts-default">
<action name="HelloWorld" class="tutorial.HelloWorld">
<result>HelloWorld.jsp</result>
</action>
</package>
</struts>
***********************************************************************************************
SayHello.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!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>Say Hello</title>
</head>
<body>
<h3>Say "Hello" to:</h3>
<s:form action="HelloWorld">
Name: <s:textfield name="name" />
<s:submit />
</s:form>
</body>
</html>
***********************************************************************************************
HelloWorld.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!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>Hello</title>
</head>
<body>
<h3><s:property value="name" /></h3>
</body>
</html>
***********************************************************************************************
HelloWorld.java
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorld extends ActionSupport {
private static final long serialVersionUID = 1L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String execute() {
name = "Hello, " + name + "!";
return SUCCESS;
}
}
***********************************************************************************************
运行http://localhost:8080/Struts2_HelloWorld/SayHello.jsp,就会报HTTP Status 404 - /Struts2_HelloWorld/HelloWorld的错误。
从http://localhost:8080/Struts2_HelloWorld/HelloWorld.action可以看到:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
There is no Action mapped for namespace / and action name HelloWorld. - [unknown location] com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186) org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:494) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.
***********************************************************************************************
解决:struts.xml文件名错误,改正后http://localhost:8080/Struts2_HelloWorld/HelloWorld.action可以看到