这是我的目录结构d:/Program files/Apache Software Foundation/Tomcat 6.0/webapps/myapp/
myapp是我自己创建的文件夹 里面有WEB-INF文件夹 WEB-INF里有web-xml和一个classes文件夹 
classes文件夹里放的servlet: Test.java和Test.class 编译没问题
以上从myapp开始都是自己创建的web-xml是这样:<?xml   version= "1.0 "   encoding= "ISO-8859-1 "?><!DOCTYPE   web-app
PUBLIC   "-//Sun   Microsystems,   Inc.//DTD   Web   Application   2.3//EN "
"http://java.sun.com/dtd/web-app_2_3.dtd "><web-app> 
<display-name> My   Web   Application </display-name>
<description>
A   application   for   test.
</description>
<servlet>
<servlet-name> Test </servlet-name>
<display-name> Test </display-name>
<description> A   test   Servlet </description>
<servlet-class> Test </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> Test </servlet-name>
<url-pattern> /Test </url-pattern>
</servlet-mapping>
</web-app> 从浏览器输入http://localhost:8080/myapp/Test 
一直报错404 我知道多半是路径的问题找不到TEST 运行TOMCAT的例子都是正常
但实在看不出来哪里写错了 谢谢!

解决方案 »

  1.   

    import   java.io.IOException;
    import   java.io.PrintWriter;
    import   javax.servlet.ServletException;
    import   javax.servlet.http.HttpServlet;
    import   javax.servlet.http.HttpServletRequest;
    import   javax.servlet.http.HttpServletResponse;
    public   class   Test   extends   HttpServlet   {
    protected   void   doGet(HttpServletRequest   request,   HttpServletResponse   response)
    throws   ServletException,   IOException   {
    PrintWriter   out=response.getWriter();
    out.println( " <html> <body> <h1> This   is   a   servlet   test. </h1> </body> </html> ");
    out.flush();
    }
    } 这是servlet Test.java 但我觉得不应该是servlet的问题
      

  2.   

    另人蛋疼 怎么连个包也没有http://localhost:8080/Test
      

  3.   

    用http://localhost:8080/Test还是不行 
    这个应该跟包没什么关系吧
      

  4.   

    控制台和 $CATALINA_HOME/logs/*.log
    看下日志有什么错误信息吗?
      

  5.   

    每次修改web.xml之后都要重启服务
    web.xml这个你没有命名错误吧,还有就是你仔细检查你的各个文件名是不是都对
    我现在也在学习jsp,我的测试例子就成功了,不行我把我的过程跟你交流一下
      

  6.   

    解决了
    查了控制台的LOG文件里说的
    严重: Parse Fatal Error at line 1 column 24: XML version "1.0    " is not supported, only XML 1.0 is supported.
    org.xml.sax.SAXParseException: XML version "1.0    " is not supported, only XML 1.0 is supported.我才发现我的WEB.XML里的这几行
    <?xml version= "1.0 " encoding= "ISO-8859-1 "?><!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN "
    "http://java.sun.com/dtd/web-app_2_3.dtd ">
    里面好多地方都多打了空格 因为我是复制网上的例子 一直没注意