我想问一下,我这个无包的servlet怎么总是在tomcat上出不来,总是提示404错误 我的classpath是这样的  C:\jdk1.5.0_16\jre\lib\rt.jar;.;C:\Tomcat 5.5\common\lib\servlet-api.jar 同时我也将servlet-api.jar文件放在了C:\jdk1.5.0_16\jre\lib\ext下 javac可以编译成功,也把class文件放在了C:\Tomcat 5.5\webapps\ROOT\WEB-INF\classes下,但是是上了tomcat就不行了,先谢谢各位了。。

解决方案 »

  1.   

    看看ROOT\WEB-INF\的web.xml是否把servlet的mapping配进去了
      

  2.   

    我的web。xml文件是这样的
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!--
     Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    --><web-app 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"
        version="2.4">  <display-name>Welcome to Tomcat</display-name>
      <description>
         Welcome to Tomcat
      </description><!-- JSPC servlet mappings start -->    <servlet>
            <servlet-name>org.apache.jsp.index_jsp</servlet-name>
            <servlet-class>org.apache.jsp.index_jsp</servlet-class>
        </servlet>    <servlet-mapping>
            <servlet-name>org.apache.jsp.index_jsp</servlet-name>
            <url-pattern>/index.jsp</url-pattern>
        </servlet-mapping><!-- JSPC servlet mappings end --></web-app>
      

  3.   

    加多一个
    <servlet> 
            <servlet-name>你的servlet名字</servlet-name> 
            <servlet-class>你的servlet class的package路径</servlet-class> 
        </servlet>     <servlet-mapping> 
            <servlet-name>对应上面的servlet名字</servlet-name> 
            <url-pattern>你自己定义的url</url-pattern> 
        </servlet-mapping>
      

  4.   

     <servlet> 
            <servlet-name>HelloServlet</servlet-name> 
            <servlet-class>C:\Tomcat 5.5\webapps\ROOT\WEB-INF\classes</servlet-class> 
        </servlet>     <servlet-mapping> 
            <servlet-name>HelloServlet</servlet-name> 
            <url-pattern>http://localhost:8080/servlet</url-pattern> 
        </servlet-mapping>这样加?钢材这样加了以后,服务器启动不了了
      

  5.   

    <servlet-class>C:\Tomcat 5.5\webapps\ROOT\WEB-INF\classes </servlet-class> 
    这里指的是package路径喔
      

  6.   

    我无包名阿,初学,不要见怪直接是
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
      

  7.   

    既然是在tomcat上显示不出来,我想应该是个项目demo了,
    那就不应该放到ROOT\WEB-INF\classes
    应该放到webapps/下你自己建立的工程的demo\WEB-INF\classes下
    理解吧
      

  8.   

    <servlet-class>C:\Tomcat 5.5\webapps\ROOT\WEB-INF\classes </servlet-class> 
    没有包名 那就直接写你的类名唉