This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in compiling servlet

 
sasank manohar
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic