程序很简单新建动态网页工程Struts2_HelloWorld
将Struts2.16中的lib文件考到WebContent/lib下,新建index.html;struts.xml;web.xml
index.html在WebContent下;struts.xml在src下;web.xml在WEB-INF下
web.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Struts2_HelloWorld</display-name>
  <filter>
   <filter-name>Struts2</filter-name>
   <filter-class>org.apache.struts.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>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>
sttruts.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"/>
</struts>
最后导出war到webapp下!
http://localhost:8080/Struts2_HelloWorld/
结果如下:
HTTP Status 404 -type Status reportmessagedescription The requested resource () is not available.
Apache Tomcat/6.0.18请哪位大虾帮忙解决一下,不胜感激!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    我知道时页面找不到啊!时怎么回事?Tomcat绝对没问题,别的页面可以打开
      

  2.   

    经过对BUG的研究!终于解决了分享一下!
    导包的时候注意不要把所有的包都导进去,不然就会出现Unable to load configuration. - bean - jar:file:/d:/Tomcat6/webapps/EJBBookStoreWebModule/WEB-INF/lib/struts2-convention-plugin-2.1.6.jar!/struts-plugin.xml:30:119
    此类的错误,这应该是struts2.1.6的一个bug吧~~~HelloWorld.jsp<%@ taglib prefix="s" uri="/struts-tags" %><html>
        <head>
            <title>Hello World!</title>
        </head>
        <body>
            <h2><s:property value="message" /></h2>
        </body>
    </html>*****************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"><welcome-file-list>
        <welcome-file>HelloWorld.jsp</welcome-file>
    </welcome-file-list>
       <filter>
            <filter-name>struts</filter-name>
            <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
            <init-param>
            <param-name>actionPackages</param-name>
            <param-value>com.mycompany.myapp.actions</param-value>
            </init-param>
        </filter>    <filter-mapping>
            <filter-name>struts</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>   
    </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="tutorial" extends="struts-default">
            <action name="HelloWorld" class="tutorial.HelloWorld">
                <result>/HelloWorld.jsp</result>
            </action>
            <!-- Add your actions here -->
        </package>
    </struts>*******************************************