Solved

Compiling a Java Servlet

Posted on 2003-11-04
8
390 Views
Last Modified: 2010-04-01
I have installed JSDK2.0 on machine to run the servlets. I have HelloWorld servlet in "C:\JSDK2.0\examples" directory. I am having problem compiling this servlet. I get the following error.

C:\JSDK2.0\examples>javac HelloServletWorld.java
HelloServletWorld.java:4: cannot resolve symbol
symbol : class HttpServlet
location: class HelloServletWorld
public class HelloServletWorld extends HttpServlet {
^
HelloServletWorld.java:6: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloServletWorld
public void doGet(HttpServletRequest request, HttpServletResponse response)
^
HelloServletWorld.java:6: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloServletWorld
public void doGet(HttpServletRequest request, HttpServletResponse response)
^
3 errors

I know there must error in setting the path and classpath variables. I set the path = "C:\jdk1.3.1_07\bin;C:\jsdk2.0\bin" and classpath ="C:\jsdk2.0\lib\jsdk.jar". Can anybody tell me what is wrong in the settings? Can help would be appreciated.

Thank you
0
Comment
Question by:Kiranmayee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 15

Expert Comment

by:jimmack
ID: 9679358
You need to include the servlet.jar file in your classpath.

eg.  If it is in c:\jakarta-tomcat\commons\lib\servlet.jar

Use:

javac -g -classpath c:\jakarta-tomcat\commons\lib\servlet.jar HelloServletWorld.java

You might want to consider using the "-d" option too, to tell the compiler where to write the .class files
0
 

Author Comment

by:Kiranmayee
ID: 9679439
I am using JSDK server not tomcat server. I got it fixed. I set the path = "C:\jdk1.3.1_07\bin;C:\jsdk2.0\bin" and classpath ="C:\jsdk2.0\lib\jsdk.jar". I included the "import javax.servlet.http.*;" statement in my servlet. Thank you for your immediate response.

Thank you
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9679584
Sorry.  I mis-read that as j2sdk :-(

You need to include the .JAR file that contains the javax.servlet... classes.  I'm not sure what it's called in JSDK.  Have a look to see what is in the \lib directory.

You can use the following to see what is in a jar file:

jar tvf filename.jar
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:evedder
ID: 9683123
the jar you are looking for is servlet.jar as jimmack says but I dont remember either where is located
0
 

Author Comment

by:Kiranmayee
ID: 9683629
I downloaded JSDK from http://java.sun.com/products/servlet/archive.html. I don't have servlet.jar , i only see jsdk.jar in lib directory .  I included the "import javax.servlet.http.*;" statement in my servlet and it works. Thank you guys for your comments.
0
 

Expert Comment

by:paragagarwal
ID: 9712452
First set your servlet.jar in the classpath and then complie it.
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 10882470
PAQed, with points refunded (50)

CetusMOD
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question