环境:
Apache:2.2.10
Tomcat:5.5.27D:\MyApps 为我建立的虚拟目录的位置我然后在这个目录下建立一个目录WEB-INF目录和一个文件web.xml,并在WEB-INF中建立classes目录现在我通过http://localhost/MyApps 可以成功访问到这个虚拟目录。现在的web.xml中只有如下的内容:<?xml version="1.0" encoding="utf-8"?>
<web-app>
  <welcome-file-list>
   <welcome-file>index.html</welcome-file>
   <welcome-file>index.htm</welcome-file>
   <welcome-file>index.jsp</welcome-file>  
  </welcome-file-list>  
 </web-app>现在,放个静态的html文件到d:\MyApps下,是可以成功访问的。我写了个servlet,很简单的,将编译成功的class文件拷贝到WEB-INF/classes中。
然后修改web.xml中的文件内容为:
<?xml version="1.0" encoding="utf-8"?>
<web-app>
  <servlet>
<servlet-name>hello</servlet-name>
<servlet-class>HelloServlet</servlet-class>
 </servlet>
  
  <servlet-mapping>
   <servlet-name>hello</servlet>
   <url-pattren>/TestServlet</url-pattern>
  </servlet-mapping>
  
  <welcome-file-list>
   <welcome-file>index.html</welcome-file>
   <welcome-file>index.htm</welcome-file>
   <welcome-file>index.jsp</welcome-file>  
  </welcome-file-list>
  
 </web-app>
现在连http://localhost:8080/MyApps下的基本的静态基本html文件都访问不到,更不要提http://localhost:8080/MyApps/TestServlet了??这是什么原因啊??搞了一整天了,郁闷哈..每改动一次我都重新启动过tomcat,还是出这样的问题!

解决方案 »

  1.   

    web.xml根本没解析正确。
    servlet-class>HelloServlet</servlet-class>HelloServlet在包中么?packagename.HelloServlet
      

  2.   

    xml解析不了。。好可能是路径或都JAVA的名不搭配
      

  3.   

    第一、先http://localhost:8080看看自己的tomcat有问题没我然后在这个目录下建立一个目录WEB-INF目录和一个文件web.xml
    我想请问一下你的web.xml是在哪个目录下?
    web.xml放到WEB-INF/下面去
    配置没问题(如果没有package的话)第二、如果你有package的话就不能直接把.class文件拷贝到classes目录下去,也要建跟package一样的目录结构
    然后把.class文件拷贝到下面去,当然<servlet-class>HelloServlet</servlet-class>还是要改成<servlet-class>packageName.HelloServlet</servlet-class>
      

  4.   


    localhost:8080没有问题。
    web.xml是放到WEB-INF下的,没有使用package
      

  5.   

    这次应该可以解决了,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">
    你的掉了满多所以不行
    建议这个部分去别的地方拷贝或者由ide生成,免得容易出错
      

  6.   

    自己解决了,去掉
      <welcome-file-list>
              <welcome-file>index.html</welcome-file>
              <welcome-file>index.htm</welcome-file>
              <welcome-file>index.jsp</welcome-file>              
      </welcome-file-list>
     这个就好了
      

  7.   

    web.xml<welcome-file-list> 
              <welcome-file>index.html </welcome-file> 
              <welcome-file>index.htm </welcome-file> 
              <welcome-file>index.jsp </welcome-file>              
      </welcome-file-list>