目录结构如下:
根目录在 D:/Tomcat 6.0/webapps/Struts2
index.jsp:              D:/Tomcat 6.0/webapps/Struts2/index.jsp
web.xml:                D:/Tomcat 6.0/webapps/Struts2/WEB-INF/web.xml
struts.xml:              D:/Tomcat 6.0/webapps/Struts2/WEB-INF/classes/struts.xml
struts.properties        D:/Tomcat 6.0/webapps/Struts2/WEB-INF/classes/struts.properties
HelloStruts2World.class  D:/Tomcat 6.0/webapps/Struts2/WEB-INF/classes/hello/HelloStruts2World.classweb.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">    <filter>
        <filter-name>Struts 2 filter </filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>Struts 2 filter </filter-name>
        <url-pattern>/* </url-pattern>
    </filter-mapping>
   
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp </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>
    <package name="hello" extends="struts-default">
<action name="HelloStruts2World" class="hello.HelloStruts2World">
<result name="success">/index.jsp </result>
</action>
</package>
</struts>
**************************************************************************************index.jsp<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@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=UTF-8">
<title>Hello Struts 2 World Result Page </title>
</head>
<body>
<h2>Hello World! </h2>
Struts 2 Message: <s:property value="message" default="Guest." />
<s:form method="GET" action="hello/HelloStruts2World.action">
Enter your name: <s:textfield name="userName" />
<s:submit value="Submit" />
</s:form>
</body>
</html>
index.jsp可以正常显示,但是点击Submit按钮会出现错误:
There is no Action mapped for action name HelloStruts2World. - [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) 

解决方案 »

  1.   

    命名空间错了!!!<s:form method="GET" action="hello/HelloStruts2World.action">
    这里错误了!
    直接应该是:HelloStruts2World.action
    hello应该是命名空间,你的没有定义namespace="hello"配置文件添加命名空间,这样就好了:
    <package name="hello" extends="struts-default" namespace="hello"> 
      

  2.   

    或者
    <s:form method="GET" action="HelloStruts2World">.action可以不用加的!
      

  3.   

    TO xblue3
    谢谢回答照你说的做了
    可是还是一样的错误
      

  4.   

    是不是action的代码出问题了!我前几天因为配置文件一个字母的大小写问题怎么都出不来,差点没砸电脑了!
      

  5.   

    action的代码:
    package hello;import com.opensymphony.xwork2.ActionSupport;
    public class HelloStruts2World extends ActionSupport {
    private String userName;
    public String getUserName() {
    return userName;
    }
    public void setUserName(String userName) {
    this.userName = userName;
    }
    private String message;
    public String getMessage() {
    return message;
    }
    @Override
    public String execute() {
    message = "Hello, " + userName + ".";
    return SUCCESS;
    }
    }
    会不会是Tomcat有什么特别的设置啊
      

  6.   

    <s:form method="GET" action="hello/HelloStruts2World.action">
    改成
    <s:form method="GET" action="HelloStruts2World.action">
      

  7.   

    再不行,就用HTML标签FORM提交吧
      

  8.   

    命名空间要以/开头,你的命名空间应该配置为:namespace="/hello"。
    才能用hello/hello/HelloStruts2World.action