Servlet problem

Discussions

Web tier: servlets, JSP, Web frameworks: Servlet problem

  1. Servlet problem (5 messages)

    I'm really new to Servlet and JSP programming.I downloaded Tomcat and have the server running. When I try and complie this code I get errors.
    import java.io.*;
    import javax.servlet.http.*;
    public class MyHelloWorld extends HttpServlet
    {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
    {
    response.setContentType("text/html");
    PrintWriter out=response.getWriter();
    out.println("<html>");
    out.println("<body>");
    out.println("<head>");
    out.println("<title>Hello World,!</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Hello World</h1>");
    out.println("</body>");
    out.println("</html>");
    }
    }

    these are the errors I get:MyHelloWorld.java:2: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    MyHelloWorld.java:3: cannot find symbol
    symbol: class HttpServlet
    public class MyHelloWorld extends HttpServlet
                                      ^
    MyHelloWorld.java:5: cannot find symbol
    symbol : class HttpServletRequest
    location: class MyHelloWorld
            public void doGet(HttpServletRequest request,HttpServletResponse respons
    e) throws IOException
                              ^
    MyHelloWorld.java:5: cannot find symbol
    symbol : class HttpServletResponse
    location: class MyHelloWorld
            public void doGet(HttpServletRequest request,HttpServletResponse respons
    e) throws IOException
                                                         ^
    4 errors

    Please let me know what I am doing wrong! I have a huge assignmnet based on Servlets due this tuesday and I can't even get the sample code to run!

    Threaded Messages (5)

  2. Check your classpath[ Go to top ]

    Make sure the servlet JAR is in your class path when you compile. Good luck with your assignment.
  3. Check your classpath[ Go to top ]

    I dont know what you mean by that. Could you tell me an example. My prof told me to compile it like a normal java program.
  4. hai neha, installing tomcat is not enough , u must have servlet api to compile a servlet program. if u have complete j2ee software onto your system and even then u get this errors, then u have to set classpath.
         And one more thing in your code u have to import javax.servlet.* class also and ur doget() method must throw servletexception also.
  5. You should check your classpath[ Go to top ]

    I don't know whether you use console to complie your java programme or not. If you use the console, first you should set the environment variable, for example, you should
    c:\>set classpath=%classpath%;%CATALINA_HOME%/common/lib/servlet-api.jar;
    CATALINA_HOME is the installed directory of your Tomcat. Such us c:\tomcat-5.0.28.
  6. You should check your classpath[ Go to top ]

    oh thanks!! It works!