Results 1 to 3 of 3

Thread: HttpServlet

  1. #1
    paul21 is offline Member
    Join Date
    Nov 2009
    Posts
    12
    Rep Power
    0

    Default HttpServlet

    Hi i am trying to set up a Tomcat server and keep getting the a few errors when trying to compile... looks like something to do with the inherited HttpServlet but am not too sure, am i right in thinking that HttpServlet is an automatic class or do i have to create that class?

    here is the code

    Java Code:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    
    public class HelloWorld extends HttpServlet {
      public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
          throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println( "<HTML> <BODY> <H1>Hello World !</H1> </BODY></HTML>");
      }
    }[B][/B]

    and here are the errors

    Java Code:
    HelloWorld.java:2: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    HelloWorld.java:3: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    HelloWorld.java:5: cannot find symbol
    symbol: class HttpServlet
    public class HelloWorld extends HttpServlet {
                                    ^
    HelloWorld.java:6: cannot find symbol
    symbol  : class HttpServletRequest
    location: class HelloWorld
      public void doGet(HttpServletRequest request,
                        ^
    HelloWorld.java:7: cannot find symbol
    symbol  : class HttpServletResponse
    location: class HelloWorld
                        HttpServletResponse response)
                        ^
    HelloWorld.java:8: cannot find symbol
    symbol  : class ServletException
    location: class HelloWorld
          throws ServletException, IOException {
                 ^
    6 errors
    please help thanks

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    we need to use the servlet-api.jar file from the tomcat lib folder in the javac classpath.

  3. #3
    paul21 is offline Member
    Join Date
    Nov 2009
    Posts
    12
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 11-04-2009, 02:02 PM
  2. HTTPServlet library
    By Robert_85 in forum Advanced Java
    Replies: 1
    Last Post: 04-10-2009, 09:28 PM
  3. Request Scope in HttpServlet
    By rkpasunoori in forum Java Servlet
    Replies: 1
    Last Post: 11-13-2008, 06:43 AM
  4. HttpServlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-17-2007, 08:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •