• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with compiling servlets

 
Aparanji Raju
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need some help with running servlets on my system.
Currently i have java1.2.1 running on my system.I also have jsdk2.0 installed.I dont have any problem with running the servletrunner from C:\jsdk2.0\bin.
My problem is i have a correct code in my examples class.
The error it is giving is that
Package javax.servlet not found in import.
Package javax.servlet.http not found in import.
Superclass HttpServlet of class MyServlet2 is not found.
i have the javax,servlet,http folders(one within another respectively) in a folder called src in jsdk2.0
Even adding C:\jsdk2.0\src to my path in autoexec.bat file is not helping.
What shd i do.
In case if there is any error in my code,please check it.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet2 extends HttpServlet
{
PrintWriter out;
public void service(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
res.setContentType("text/html");
out=res.getWriter();
out.println("<html><body bgcolor=\"#ffffcc\" text=\"#660066\" background=\"c:/pictures/csoup.gif\">");
out.println("<h1>Angels are in Heaven but their errands are around us</h1>");
out.println("<img src=\"c:/pictures/Firework.jpg\" align=right></img>");
}
}
Thanks a lot.
Aparanji.
 
Angela Poynton
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to have server.jar and servlet.jar from JSDK in your classpath. If you don't have these then that's where you're problem lies.
 
Todd M Bush
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to compile with the path of the servlet.jar. something like this....
(on NT)
javac -classpath .;c:\jsdk2.2\servlet.jar <yourJavaClass.java>
 
AJ Dussault
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aparanji,
I made a simple batch file called compile.batch that had all of my relevant paths in it.

javac -classpath lib\servlet.jar; servlets\%1
so at the command prompt, I would type "compile TestServlet.java" and it would compile the TestServlet.java in the servlet directory (assuming you are 'sitting' one directory above it)
A lot less typing.... :-)
Amanda
 
Aparanji Raju
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Todd and Angela.Sorry for replying late but giving the commands as u suggested are giving me the same errors about "package javax not found in import" .Should i try reinstalling jsdk again?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I would not mess with the JSDK - that is no-longer the "reference" release for servlet and JSP development as I read the announcements at java.sun.com. Sun gave all of the code to the Apache organization. The Tomcat package is available at:
http://jakarta.apache.org/
It is good enough to use as a working server in addition to being good for development.
 
Aparanji Raju
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for responding Mr.Brogden.I just started learning servlets.I am sorry to say that I havent started with JSP yet.
So,If I download Tomcat package will it be compatable with the jdk1.2.1 that I have on my system?
Thanks again,
Aparanji
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

my suggesstion to you is to install java web server on your
machine. try to run servlets thr' it
if you don't like my suggesstion forgive me please.
bye
 
Aparanji Raju
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks tiger.Its not the question of not liking your suggestion.The fact is that I am used to and comfortable with working with servlets from jsdk2.0 .I will install java web server and acquaint myself with it.
Thanks.
 
Vikrant
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Raju,
Edit your autoexec.bat file residing in C:\ and add the following line of code after the line where you are setting the path :
set classpath=c:\jsdk2.0\lib\jsdk.jar
save the file and restart the computer.
Try compiling your servlets now.
It shall help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic