jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Problem in compiling servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem in compiling servlet" Watch "Problem in compiling servlet" New topic

Problem in compiling servlet

sasank manohar
Ranch Hand

Joined: Feb 14, 2008
Posts: 186
I am trying to compile this servlet,
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws
PrintWriter out=res.getWriter();
out.println("<HEAD><TITLE> Hello World</TITLE></HEAD>");
out.println("<BIG>Hello World </BIG>");
But , I am getting these errors.
C:\JavaWebServer2.0\servlets>javac HelloWorld.java
HelloWorld.java:2: Package javax.servlet not found in import.
import javax.servlet.*;
HelloWorld.java:3: Package javax.servlet.http not found in import.
import javax.servlet.http.*;
HelloWorld.java:5: Superclass HttpServlet of class HelloWorld not found.
public class HelloWorld extends HttpServlet{
3 errors
Can anyone please explain me from the beginning to end , how to set classpath, complie and run the servlet. I am really going mad about this, by setting class path. From where should I compile and what are all the things I need to download. Please........

Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

First off (from my experience) getting mad doesn't help.
I understnad your frustration, but try to read each word
carefully, trust me I was there....
Now, I haven't used JWS2.0. For servlets I use jsdk2.1
or tomcat (a little difficult) and now JRun.
The easiest I found was JSDK.
Since you are using JWS2.0 hopefully you read the documentation
whether it supports servlet api or not. If it does, then
add all the .jar files to your classpath. You do this as below:
you are on Windows....hopefully...
set PATH=%PATH%;C:\JavaWebServer2.0\lib\this.jar
set PATH=%PATH%;C:\JavaWebServer2.0\lib\that.jar
assuming the path to the jar file is correct. Locate the
correct directory in which the *.jar files are and then add
After this you should be able to compile your .java file
Now to access the servlet, you need to look at the
documentation. Sorry but I can't help much with JWS2.0 which
I haven't used. If you could download JSDK2.1 let me know I
could be more elaborate.
- satya

Take a Minute, Donate an Hour, Change a Life
I agree. Here's the link: http://aspose.com/file-tools
subject: Problem in compiling servlet
jQuery in Action, 3rd edition