Solved

Compiling a Java Servlet

Posted on 2003-11-04
8
394 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
This article outlines the struggles that Macs encounter in Windows-dominated workplace environments – and what Mac users can do to improve their network connectivity and remain productive.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

635 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