Solved

Compiling a Java Servlet

Posted on 2003-11-04
8
376 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
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now