tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From " \ listanand@gmail.com" <listan...@gmail.com>
Subject Servlet Error
Date Mon, 08 Jun 2009 11:25:36 GMT
Hi all,

I am new to Tomcat/Apache, and have just about started to learn JSP/Servlets
as well.  I just wrote my first Hello world servlet (code below) and tried
to run it, but got several errors. Here's exactly what I did:
1. I wrote "Hello.java" (code below) and put it in /webapps/ROOT directory
2. I tried to compile it ("javac Hello.java") but got errors. (see below)

I would appreciate if someone would tell me what I am missing. Also, after
the servlet compiles, do I need to put it in WEB-INF?

Just for the records, I try to access the servlet using
http://localhost:8080/Hello and I am using Java version 1.6.

Thanks in advance.



---CODE---
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Hello extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("Hello World");
  }
}



--ERRORS--

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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message