File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem in compiling servlet" Watch "Problem in compiling servlet" New topic
Author

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
ServletException,IOException{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<HTML>");
out.println("<HEAD><TITLE> Hello World</TITLE></HEAD>");
out.println("<BODY>");
out.println("<BIG>Hello World </BIG>");
out.println("</BODY></HTML>");
}
}
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........
thanks....
sdev

"SCJP5 | SCWCD5| DEVELOPER"
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
them.
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.
Regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem in compiling servlet