Solved

Compiling a Java Servlet

Posted on 2003-11-04
8
386 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
java cyclic graphs 15 219
issue with pdf generation 2 96
main method of string class 3 122
running on tomcat not jboss eap 7.0 3 30
Arrow Electronics was searching for a KVM  (Keyboard/Video/Mouse) switch that could display on one single monitor the current status of all units being tested on the rack.
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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