GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes javax.servlet not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "javax.servlet not found" Watch "javax.servlet not found" New topic
Author

javax.servlet not found

Abhinav Pandey
Ranch Hand

Joined: Sep 28, 2006
Posts: 50
Hello ranchers i am very new to servlets. I have jdk1.5 installed in my pc
along with Sun Studio EnterpriseEdition
Whenever i try to compile my code (having import javax.servlet.*) from command prompt, it gives a compiler error of above package not found. Whereas my normal corejava codes compiles fine.Kindly tell me how to get the package in the path


SCJP 5.0, SCWCD 1.4
SCJWSD5 in progress
Dinuka Arsakularatne
Ranch Hand

Joined: Aug 12, 2006
Posts: 198
you need to install tomcat5.0 and j2ee 1.5 sdk as well. then set the eviroment variables as follows; (note that this is relative to where i have installed the relevant applications)

ANT_HOME - C:\Sun\AppServer\lib\ant
CLASSPATH - .;C:\apache-tomcat-5.5.17\apache-tomcat-5.5.17\common\lib\servlet-api.jar;C:\apache-tomcat-5.5.17\apache-tomcat-5.5.17\common\lib\jsp-api.jar;

J2EE_HOME - C:\Sun(where you install the j2ee sdk)
JAVA_HOME - C:\Sun\AppServer\jdk(where you have installed the j2se jdk)
PATH - "C:\Sun\AppServer\bin";"C:\Sun\AppServer\jdk\bin";"C:\Sun\AppServer\lib\ant\bin";%PATH%
thats about it... after that just compile your code from the command promt and check... hope this helped.


if who i am is what i have, and what i have is lost, then who am i?<br /> <br />SCJP 5.0<br />SCWCD 1.4<br />SCBCD preparing
bhagavatula indu sekhar
Ranch Hand

Joined: Sep 17, 2006
Posts: 34
i think the edition you are using doesn't contain classes which are necessary for servlets.

download jsdk2.1 and set

On windows system :

classpath to rootdirectory:\jsdk2.1\servlet.jar;rootdirectory:\jsdk2.1\server.jar

Example : classpath is D:\jsdk2.1\servlet.jar;D:\jsdk2.1\server.jar;
classpath is an user defined environment variable.
if it is not present then create it.

now after setting this compile your servlet.i think it must work.

i think i answered your question properly and this is the first reply for a question in this community.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Abhinav Pandey:
Hello ranchers i am very new to servlets. I have jdk1.5 installed in my pc
along with Sun Studio EnterpriseEdition
Whenever i try to compile my code (having import javax.servlet.*) from command prompt, it gives a compiler error of above package not found. Whereas my normal corejava codes compiles fine.Kindly tell me how to get the package in the path


All you need is your servlet library on your classpath. Typically servlet.jar or servlet-api.jar.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by bhagavatula indu sekhar:
download jsdk2.1


??

Moreover, SDK doesn't, typically, include servlet library.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42038
    
  64
Originally posted by Adeel Ansari:
Moreover, SDK doesn't, typically, include servlet library.


JSDK -as opposed to the any of the Java SE/EE SDKs- used to be short for "Java Servlet Dev Kit", and it did include the jar files. But the term JSDK was dropped a while ago. The servlet jars are now available here, or as part of a Tomcat installation.
[ November 08, 2006: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

See:
http://faq.javaranch.com/view?CompilingServlets

Moving to Java In General where javac and classpath issues are discussed.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Petrus Pelser
Ranch Hand

Joined: Feb 20, 2006
Posts: 132
You need to add [Java EE directory]\lib\javaee.jar to your classpath variable.

If you are still using J2EE instead of Java EE 5, you need to add [J2EE directory]\lib\j2ee.jar to your classpath.
 
GeeCON Prague 2014
 
subject: javax.servlet not found