日期:2014-05-18  浏览次数:20760 次

*********来看看:Struts2的HelloWorld 怎么都不能运行,高手帮忙 ***************
写了一个Struts2的HelloWorld 怎么都不能运行,高手帮忙看看?多谢。
文件的结构:

 ---Hello
  --index.html
  --WEB-INF
  --web.xml
  --lib(struts2所有的jar)
  --classes 
  --struts.xml


index.html里面就一个HelloWorld,
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>
<include file="struts-default.xml"/>
</struts>


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>Hello</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>


运行 localhost:8000/Hello/index.html
或者运行 运行 localhost:8000/Hello/  
都说 HTTP Status 404 - /Hello/index.html 删掉web.xml就正常,请高手看看哪里出错了。

多谢多谢!!

------解决方案--------------------
报错首先看日志文件,不然除非你把文件都传上来,要不很难知道你错在什么地方

出现404的原因有很多,原因是找不到文件,当项目没有启动起来的时候,那么项目下的所有的文件都是不可见的
按照你的情况,出现的可能就是项目没有启动起来,检查filter类在启动的时候是否报出异常

还有html是不经过应用服务器解析的
------解决方案--------------------
struts.xml 放到WEB-INF目录下?
------解决方案--------------------
// C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\HelloServlet does not exist or is not a readable directory 
=========================================
重新编译 HelloServlet 未找到 
HelloServlet没有配置到webapps下面啦

编译完后 看看webapps下面有没有HelloServlet这个文件夹

估计是对应错了 存到别的地方去了 仔细检查一下
------解决方案--------------------
struts-xml 配置文件对吗?
好像有问题哦,看这个样子很可能是类似path=/xx.do这样的东西没有配置好
------解决方案--------------------
这里面要FILTER干什么?你的页面中都没有的呀!
好乱呀!不怎么理解!
一般里面还有SERVLET的配置吧!

------解决方案--------------------
struts-default.xml
在哪呢?
------解决方案--------------------
宝贝这是webwork