还有就是如何编译servlet程序
我象编译平常java程序一样编译servlet却出现错误,这是怎么回事,请高手指教

解决方案 »

  1.   

    你的url有错误.
    你在jsp里面的action应该是 "/HelloWorldExample"
      

  2.   

    那个已经搞定了,现在是让我知道怎么编译servlet吧
      

  3.   

    <servlet-mapping>
      <servlet-name>HelloWorldExample</servlet-name>      
       <url-pattern>/servlet/HelloWorldExample</url-pattern>  
    </servlet-mapping> 你改成这样试试
      

  4.   

    我的HelloWorldExample.java的代码是:
    /* $Id: HelloWorldExample.java,v 1.2 2001/11/29 18:27:25 remm Exp $
     *
     */import java.io.*;
    import java.text.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;/**
     * The simplest possible servlet.
     *
     * @author James Duncan Davidson
     */public class HelloWorldExample extends HttpServlet {
        public void doGet(HttpServletRequest request,
                          HttpServletResponse response)
            throws IOException, ServletException
        {
            ResourceBundle rb =
                ResourceBundle.getBundle("LocalStrings",request.getLocale());
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();        out.println("<html>");
            out.println("<head>");     String title = rb.getString("helloworld.title");     out.println("<title>" + title + "</title>");
            out.println("</head>");
            out.println("<body bgcolor=\"white\">"); // note that all links are created to be relative. this
    // ensures that we can move the web application that this
    // servlet belongs to to a different place in the url
    // tree and not have any harmful side effects.        // XXX
            // making these absolute till we work out the
            // addition of a PathInfo issue     out.println("<a href=\"/examples/servlets/helloworld.html\">");
            out.println("<img src=\"/examples/images/code.gif\" height=24 " +
                        "width=24 align=right border=0 alt=\"view code\"></a>");
            out.println("<a href=\"/examples/servlets/index.html\">");
            out.println("<img src=\"/examples/images/return.gif\" height=24 " +
                        "width=24 align=right border=0 alt=\"return\"></a>");
            out.println("<h1>" + title + "</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }
    但是编译的时候却出现这样的错误:
    HelloWorldExample.java:8: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    HelloWorldExample.java:9: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    HelloWorldExample.java:17: cannot resolve symbol
    symbol  : class HttpServlet
    location: class HelloWorldExample
    public class HelloWorldExample extends HttpServlet {
                                           ^
    HelloWorldExample.java:20: cannot resolve symbol
    symbol  : class HttpServletRequest
    location: class HelloWorldExample
        public void doGet(HttpServletRequest request,
                          ^
    HelloWorldExample.java:21: cannot resolve symbol
    symbol  : class HttpServletResponse
    location: class HelloWorldExample
                          HttpServletResponse response)
                          ^
    HelloWorldExample.java:22: cannot resolve symbol
    symbol  : class ServletException
    location: class HelloWorldExample
            throws IOException, ServletException
                                ^
    6 errors
      

  5.   

    这些错误都是因为你没有把SERVLET.JAR包 导入你的SERVLET的工程中造成的。
      

  6.   

    你下载一个servlet2.3.zip放在jdk\lib下,然后用classpath指明路径就可以了
      

  7.   

    我告诉你最简单的办法:把tocmat\common\lib 下的servler.jar 文件copy 到你的
    jdk的ext 目录下。如:D:\jdk\jre\lib\ext
      

  8.   

    谢楼主,谢林中静雪,the same problem has already done
      

  9.   

    方法一: 环境变量 classpaht:%tomcat_home%\common\lib;%java_home%\lib;.;
    上面的方法是如果你在环境变量里有tomcat_home 和java_home ;如果没有,你可以直接指定
    比如:classpath c:\jdk\lib;.;c:\tomcat\lib\servler.jar方法二是:根据你刚才的回答,你说还不行,那你把这个servler.jar 放在C:\Program Files\Java\j2re1.4.2\lib\ext 下面,我想你的机器一定有这个目录,你试试吧!