http://localhost:8888/HelloWorld
试试
servlet是你的包的路径
你现在没有在包里D:\Program Files\tomcat-4.1.24\webapps\ROOT\WEB-INF\classes\servlet\HelloWorld.class
http://localhost:8888/servlet/HelloWorld

解决方案 »

  1.   

    楼上的,两种方法我都试过了,还是一样会报错啊
    type Status reportmessage /servlet/HelloWorlddescription The requested resource (/servlet/HelloWorld) is not available.
      

  2.   

    你的HelloWorld.java 怎么写的,有包(package)吗?
      

  3.   

    HellowWord写成小写试试:
    /servlet/helloworld
      

  4.   

    路径问题吧?
    你的HelloWorld.class在classes下么?
      

  5.   

    这是我的HelloWorld.java:javac通过了的
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;class  HelloWorld  extends HttpServlet
    {
    public void init(ServletConfig config) throws ServletException
    {
    super.init(config);
    } public void destroy()
    {
    super.destroy();
    } public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException ,IOException
    {
    resp.setContentType("text/html");
    PrintWriter out=new PrintWriter(resp.getOutputStream());
    out.println("<html>");
    out.println("<head><title>Hello World Output</title></head>");
    out.println("<body>");
    out.println("hello world");
    out.println("</body>");
    out.println("</html>");
    out.close();
    }}
      

  6.   

    如果放在servlet下
    要加个包
    package servlet;
    在最前边
      

  7.   

    在web.xml中加入:
    <servlet-mapping>
           <servlet-name>invoker</servlet-name>
           <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>
    try again!:)
      

  8.   


    楼上所有的方法我都试过了
    都是一样的错误谁能给我一个简单的能在浏览器里调用java的例子
      

  9.   

    如果是Tomcat
    在web.xml中加入:
    <servlet-mapping>
           <servlet-name>invoker</servlet-name>
           <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>
    还是不行的话,这样
      <servlet>
        <servlet-name>hello</servlet-name>
        <servlet-class>HelloWorld</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>hello</servlet-name>
        <url-pattern>/hello</url-pattern>
      </servlet-mapping>
    然后 http://127.0.0.1/hello访问
      

  10.   

    正如楼上说的,只要配置一下web.xml文件。就可以访问。
    给你一个全的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>
      <servlet>
        <servlet-name>ExampleServlet</servlet-name>
        <servlet-class>com.wrox.servlets.ExampleServlet</servlet-class>
      </servlet>   
      <servlet-mapping>
        <servlet-name>ExampleServlet</servlet-name>
        <url-pattern>/ExampleServlet</url-pattern>
      </servlet-mapping>
      <session-config>
        <session-timeout>30</session-timeout>
      </session-config>
    </web-app>
    其中ExampleServlet 如下:
    package com.wrox.servlets;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ExampleServlet extends HttpServlet {
      public void doGet(HttpServletRequest request, 
                         HttpServletResponse response) 
              throws ServletException, IOException {
        PrintWriter out;
        String title = "Servlet Example";
        response.setContentType("text/html");
        out = response.getWriter();
        out.println("<html><head><title>");
        out.println(title);
        out.println("</title></head><body>");
        out.println("<h1>This is an example servlet.</h1>");
        out.println("</body></html>");
        out.close();
      }  public void doPost(HttpServletRequest request, 
                          HttpServletResponse response)
              throws ServletException, IOException {
        doGet(request, response);
      } 
    }
    然后地址栏输入:http://127.0.0.1:8080/虚拟目录(应用程序目录)/ExampleServlet 
      

  11.   

    to  hhuzhj(阿金) :
    我用的是tomcat发布的请问我要把ExampleServlet.java这个文件建立在哪个目录下?
    我建在了D:\Program Files\tomcat-4.1.24\webapps\ROOT\WEB-INF\classes目录下
    在dos下的D:\Program Files\tomcat-4.1.24\webapps\ROOT\WEB-INF\classes下,用javac ExampleServlet.java也通过了D:\Program Files\tomcat-4.1.24\conf下的web.xml我也删除掉,直接用你给我的代码新建了一个然后我访问
    http://localhost:8888/servlet/ExampleServlet
    http://localhost:8888/ExampleServlet
    还是都出不来啊HTTP Status 404 - /servlet/ExampleServlet--------------------------------------------------------------------------------type Status reportmessage /servlet/ExampleServletdescription The requested resource (/servlet/ExampleServlet) is not available.
      

  12.   

    我发现我改错了文件
    我现在把
    D:\Program Files\tomcat-4.1.24\webapps\ROOT\WEB-INF\web.xml按你说的改
    了,然后再访问http://localhost:8888/ExampleServlet出现了另外一个错误:
    HTTP Status 503 - Servlet ExampleServlet is currently unavailable--------------------------------------------------------------------------------type Status reportmessage Servlet ExampleServlet is currently unavailabledescription The requested service (Servlet ExampleServlet is currently unavailable) is not currently available.
      

  13.   

    我现在把web.xml改成了
    <!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>Welcome to Tomcat</display-name>
      <description>
         Welcome to Tomcat
      </description>  <servlet-mapping>
           <servlet-name>invoker</servlet-name>
           <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping></web-app>现在我访问
    http://localhost:8888/servlet/ExampleServlet
    http://localhost:8888/servlet/HelloWorld都出现500的错误了:
    type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: Cannot allocate servlet instance for path /servlet/ExampleServletjava.lang.NoClassDefFoundError: ExampleServlet (wrong name: com/wrox/servlets/ExampleServlet)这个问题怎么解决?