最近想看tomcat的源代码 就去网上下了tomcat(6.0)的源码 部署启动没有错误后 就尝试在webapp文件夹中放了个简单web工程 Test 用Bootstrap启动tomcat后 能进http://localhost:8080/  但是想要访问所建工程中的servlet TestServlet就不行了http://localhost:8080/Test/TestServlet 报的是 HTTP Status 404 错误 不知道是不是tomcat没有加载工程 不清楚原因tomcat启动时控制台信息2012-3-23 22:46:43 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: C:\Program Files\Java\jdk1.6.0_14\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.6.0_14\bin2012-3-23 22:46:46 org.apache.coyote.http11.Http11Protocol init
 信息: Initializing Coyote HTTP/1.1 on http-8080
 2012-3-23 22:46:46 org.apache.catalina.startup.Catalina load
 信息: Initialization processed in 4933 ms
 2012-3-23 22:46:46 org.apache.catalina.core.StandardService start
 信息: Starting service Catalina
 2012-3-23 22:46:46 org.apache.catalina.core.StandardEngine start
 信息: Starting Servlet Engine: Apache Tomcat/@VERSION@
 2012-3-23 22:46:46 org.apache.catalina.startup.HostConfig deployDescriptor
 信息: Deploying configuration descriptor docs.xml
 2012-3-23 22:46:49 org.apache.catalina.startup.HostConfig deployDescriptor
 信息: Deploying configuration descriptor host-manager.xml
 2012-3-23 22:46:49 org.apache.catalina.startup.HostConfig deployDescriptor
 信息: Deploying configuration descriptor manager.xml
 2012-3-23 22:46:49 org.apache.catalina.startup.HostConfig deployDirectory
 信息: Deploying web application directory examples
 2012-3-23 22:46:50 org.apache.catalina.core.ApplicationContext log
 信息: ContextListener: contextInitialized()
 2012-3-23 22:46:50 org.apache.catalina.core.ApplicationContext log
 信息: SessionListener: contextInitialized()
 2012-3-23 22:46:50 org.apache.catalina.startup.HostConfig deployDirectory
 信息: Deploying web application directory ROOT
 2012-3-23 22:46:50 org.apache.catalina.startup.HostConfig deployDirectory
 信息: Deploying web application directory Test
 2012-3-23 22:46:50 org.apache.coyote.http11.Http11Protocol start
 信息: Starting Coyote HTTP/1.1 on http-8080
 2012-3-23 22:46:51 org.apache.jk.common.ChannelSocket init
 信息: JK: ajp13 listening on /0.0.0.0:8009
 2012-3-23 22:46:51 org.apache.jk.server.JkMain start
 信息: Jk running ID=0 time=0/169  config=null
 2012-3-23 22:46:51 org.apache.catalina.startup.Catalina start
 信息: Server startup in 4824 ms工程web.xml 文件内容
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
    <description>This is the description of my J2EE component</description>
    <display-name>This is the display name of my J2EE component</display-name>
    <servlet-name>TestServlet</servlet-name>
    <servlet-class>TestServlet</servlet-class>
  </servlet>  <servlet-mapping>
    <servlet-name>TestServlet</servlet-name>
    <url-pattern>/TestServlet</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

解决方案 »

  1.   

    “就尝试在webapp文件夹中放了个简单web工程”Tomcat下面的工程文件夹名字应该是 webapps,你确定没放错?另外conf目录下的server.xml,检查下:
    <Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
      

  2.   

          <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true"
                xmlValidation="false" xmlNamespaceAware="false">
    嗯 看了下 自动部署是为true 应该不是这个原因
      

  3.   

    你的SERVLET应该有包的吧<servlet-class>TestServlet</servlet-class>这句有错了