aspose file tools*
The moose likes Servlets and the fly likes Problem running first servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem running first servlet" Watch "Problem running first servlet" New topic
Author

Problem running first servlet

Chris Mathews
Ranch Hand

Joined: Jan 08, 2001
Posts: 46
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

Joined: Jun 03, 2000
Posts: 5040

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

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Chris Mathews
Ranch Hand

Joined: Jan 08, 2001
Posts: 46
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

Joined: Jan 28, 2001
Posts: 21
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

Joined: Jan 08, 2001
Posts: 46
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

Joined: Jan 08, 2001
Posts: 46
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

Joined: Jan 28, 2001
Posts: 21
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem running first servlet
 
Similar Threads
Servlets
Program is not compiles
Compiling
Why I don't have the import javax.servlets.http.*?
Problem in compiling servlet