This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Unable to compile servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unable to compile servlet" Watch "Unable to compile servlet" New topic

Unable to compile servlet

chailin fong

Joined: Oct 15, 2007
Posts: 10
Hi All,

I need help to compile the servlet code from HFJS



I try to compile the servlet code from HFJS

This is my file structure: C:\project1

I placed Ch1Servlet in C:\project\src;

I used Tomcat 5.028 and installed in c:\program files\tomcat 5.0

The enivornment variables I set up as

classpath .;c:\j2sdk1.4.2_16\lib\tools.jar;c:\j2sdk1.4.2_16\bin;%CATALINA_HOME%\common\lib\jsp-api.jar;%CLASSPATH%

path %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\j2sdk1.4.2_16\bin;d:\

JAVA_HOME C:\j2sdk1.4.2_16
CATALINE_HOME C:\program files\tomcat 5.0

I compile the servlet from command(DOS) prompt:

C:\>javac -classpath /project1/classes/tomcat/common/lib/servlet-api.jar
-d classes src/

import javax.servlet.*;
import javax.servlet.http.*;

public class Ch1Servlet extends HttpServlet
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException
PrintWriter out = response.getWriter();
java.util.Date today = new java.util.Date();
out.println("<html>" + "<body>" + "<h1 align=center>HF\'s Chapter1 Servlet</h1>"
+ "<br>" + today + "</body>" + "</html>");


I got 5 errors as
"package javax.servlet does not exist"
"package javax.servlet.http does not exist"
"HttpServletRequest, cannot resolve system", etc

What went wrong???
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63534

Please be sure to check the Servlets FAQ before posting questions to see if your issue has already been addressed.
[ November 12, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
subject: Unable to compile servlet
It's not a secret anymore!