Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem running first servlet

 
Chris Mathews
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am follwoing Core Servelts and Java Server Pages by Marty Hall and wrote the example given in the second chapter(Helloworld.java). The follwoing is the code :
import java.io.*;
import javax.servlets.*;
import javax.servlets.http.*;
public class HelloWorld extends HttpServlets {
public void doGet(HttpServletsRequest request,
HttpServeltsResponse response)
throws ServletsException,IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}

But after compiling I am gettting the following error
Compiling C:\jdk1.2.2\bin\HelloWorld.java
C:\jdk1.2.2\bin\HelloWorld.java:7: Package javax.servlets not found in import.
import javax.servlets.*;
^
C:\jdk1.2.2\bin\HelloWorld.java:8: Package javax.servlets.http not found in import.
import javax.servlets.http.*;
^
C:\jdk1.2.2\bin\HelloWorld.java:10: Superclass HttpServlets of class HelloWorld not found.
public class HelloWorld extends HttpServlets {
^
3 errors
Finished
I did try to set the classpath for servelt.jar and jasper.jar. But I am not a master of classpath.I might have done something wrong.I am not so sure. I am using tomcat3.2.1 Please help me as I am struggling for the last 24 hours now. I want to get going.Please tell me as detailed information as apoosible.
Thanks.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The servlet.jar file is at the foll. location:
%TOMCAT_HOME%\lib\servlet.jar
Same for jasper.jar
and the import should be:
javax.servlet.* not servlets
Pl. check with the book.
regds.
- satya
 
Chris Mathews
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still getting the same error after I corrected servlets to servlet . Now the code is :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServeltResponse response)
throws ServletException,IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}

I am getting the following error :
Compiling C:\jdk1.2.2\bin\HelloWorld.java
C:\jdk1.2.2\bin\HelloWorld.java:7: Package javax.servlet not found in import.
import javax.servlet.*;
^
C:\jdk1.2.2\bin\HelloWorld.java:8: Package javax.servlet.http not found in import.
import javax.servlet.http.*;
^
C:\jdk1.2.2\bin\HelloWorld.java:10: Superclass HttpServlet of class HelloWorld not found.
public class HelloWorld extends HttpServlet {
^
3 errors
Finished
I have tried to include the servlet.jar and jasper.jar by doing the following :
javac exists under c:/jdk1.2.2/bin
tomcat is under c:\jdk1.2.2\jakarta-tomcat-3.2.1
so I did
c:\jdk1.2.2>set CLASSPATH=.;c:\jdk1.2.2\jakarta-tomcat-3.2.1\lib\servlet.jar;c:\jdk1.2.2\jakarta-tomcat-3.2.1\jasper.jar;%classpath%
I don't know what I am doing wrong . Your help is highly appreciated.
Thanks.
 
davidlong
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you copy the servelt.jar file to the jdk.1.2.2\jre\lib\ext\ folder, you could compile your servelet as normal without any importing problems.
try it
David
 
Chris Mathews
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I am getting the following error :
Compiling D:\jdk1.2.2\bin\HelloWorld.java
D:\jdk1.2.2\bin\HelloWorld.java:11: Class HttpServeltResponse not found.
public void doGet(HttpServletRequest request,
^
D:\jdk1.2.2\bin\HelloWorld.java:14: Class HttpServeltResponse not found in void doGet(javax.servlet.http.HttpServletRequest, HttpServeltResponse).
PrintWriter out = response.getWriter();
^
2 errors
Finished
Please help me resolving these.What's wrong with the code? Your ideas are highly appreciated.
Thanks.
 
Chris Mathews
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just able to compile.I misspelt the servlet. Now I have to think how to run in local server. Help please.
Thanks.
 
davidlong
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris
Then what is problem to run your servlet?
Give us your problems here if you really need help like u did above.
David
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic