struts.xml配置<?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>
<package name="jason" namespace="/test" extends="struts-default">
<action name="hello" class="action.HelloWordAction"  method="execute">
<result name="success">/page/hello.jsp</result>
</action>
</package>
</struts>web.xml配置<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <filter>
   <filter-name>Struts2</filter-name>
   <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
   <filter-name>Struts2</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>HelloWordActionpackage action;public class HelloWordAction
{
public String message; public String getMessage()
{
return message;
} public String execute()
{
message = "Hello Word!";
return "success";
}
}运行信息:
2012-10-21 21:15:02 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Program Files\MyEclipse 6.5\bin;D:\Program Files\Tomcat 6.0\bin
2012-10-21 21:15:02 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2012-10-21 21:15:02 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 871 ms
2012-10-21 21:15:02 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2012-10-21 21:15:02 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.18
2012-10-21 21:15:04 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2012-10-21 21:15:04 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
2012-10-21 21:15:04 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2012-10-21 21:15:05 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
2012-10-21 21:15:07 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2012-10-21 21:15:07 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Unable to locate configuration files of the name struts-plugin.xml, skipping
2012-10-21 21:15:07 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2012-10-21 21:15:07 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
2012-10-21 21:15:08 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2012-10-21 21:15:08 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2012-10-21 21:15:08 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/31  config=null
2012-10-21 21:15:08 org.apache.catalina.startup.Catalina start
信息: Server startup in 6065 ms初学struts,我的访问路径是:http://localhost:8080/Struts2_HelloWord/test/hello,但是hello不起来,相应的包都导入进来了,包名。类名都配置了

解决方案 »

  1.   

    http://localhost:8080/Struts2_HelloWord/test/hello.action
    HTTP Status 404 - /Struts2_HelloWord/test/hello.action
      

  2.   

    http://localhost:8080/Struts2_HelloWord/test/hello.action
    HTTP Status 404 - /Struts2_HelloWord/test/hello.action
      

  3.   

    HelloWordAction extends ActionSupport 
      

  4.   

    404  错误?  那是你路径单词错误。  
    你先试试能不能进tomcat   然后再进自己的项目里。
      

  5.   

    你的配置里怎么是  page/hello.jsp  但是路径确实http://localhost:8080/Struts2_HelloWord/test/hello.action
    两者矛盾。
      

  6.   


    这个page/hello.jsp 我是放在WEB-INF中的,忘了把WEB-INF写上了
      

  7.   


    如果成功 返回success,跳转到hello.jsp页面
      

  8.   

    人家的package里把namespace配置成了/test
      

  9.   


    你是指HellloWordAction 这个类要继承ActionSupport?
      

  10.   

    没必要继承ActionSupport,你的page目录是放在WebRoot目录下的吗
      

  11.   

    public class HelloWordAction extends ActionSupport初学者先用这个方法吧,等你用熟了在用其他的...
      

  12.   

     <package name="jason" namespace="/test" extends="struts-default">
            <action name="hello" class="action.HelloWordAction"  method="execute">
                <result name="success">/page/hello.jsp</result>
            </action>
     </package>改成这个就行了<result name="success">/WEB-INF/page/hello.jsp</result>
      

  13.   

    <url-pattern>/*</url-pattern>
    把这个改成相应的试一试。
      

  14.   

    不知道你的问题解决了没有 我遇到了和你相同的问题  只要配置在web.xml中配置strcuts就无法显示页面  
    如果你解决了 请告诉我方法   小弟初学者 请多指教
      

  15.   

    public class HelloWordAction extends ActionSupport,execute这个方法是在ActionSupport这个类里面的哦
      

  16.   

    你的struts.xml改成我上面18楼写的应该就可以了啊。因为/WEB-INF/下的jsp都得加这个
      

  17.   

    打个断定看请求时能不能进你的方法中,如果不能进,在请求前面加上/test/hello试试
      

  18.   


    我的目录就是这样写的忘了加上去
    <result name="success">/WEB-INF/page/hello.jsp</result>