Two Laptop Bag
The moose likes Servlets and the fly likes Package javax.servlet, javax.servlet.http does not exist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic

Package javax.servlet, javax.servlet.http does not exist

Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
I am attempting to run a simple servlet to become familiar with how servlets work. I am attempting to compile something like the following code in the standard manner (using javac):

The compiler comes back saying that "package javax.servlet does not exist" and "package javax.servlet.http does not exist".
Is this a CLASSPATH problem? Do I have to go out on the Web and get the API's that javax contains, or would I have already downloaded them with JDK1.3?
Any help you could offer would be greatly appreciated.
Thank you one and all,
Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
Yes, you need to download some stuff from Sun. These classes are in the j2ee.jar in j2sdk enterprise edition.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Actually, servlets are not the part of JAVA 2.0 CORE API. So you have to download servlets separately and set your CLASSPATH accordingly.

ashok samy

Joined: Nov 03, 2000
Posts: 6
u have to download servlet development kit from the sun's site
then check if src/javax/servlet subdirectory exists
it should have java & its equivalent class files in it
if not there will be a jar file in lib directory(jsdk.jar)
extract the jar file and then u will get javax/servlet subdirectory with .class files
then copy it to your examples directory & try to run the file
it will run..

Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Please note that although you will often find suggestions to download the servlet development kit from Sun, this is not usually a good idea. Sun stopped development in the servlet development kit a long time ago, and handed over development to the Apache group.
If you wish to get started with servlets, the best thing to do is to download one of the many free servlet-capable web servers, which will give you not just the ability to compile servlets, but a way to test and run them too. The official reference implementation of the servlet container is Tomcat, available from , but if you look through th epast messages in this forum you will see that many people have problems installing it and getting it to run. I personally use Resin, from http://www, which runs very fast, and is usually a lot easier to get working.
Both of these come with examples and documentation, so it's usually worth downloading one of them, even just for reference.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
Thank you all! You've all been very helpful.
Prasad Charasala
Ranch Hand

Joined: Nov 02, 2000
Posts: 67
I agreee with Frank. Ashok, If you want to put something in the jar file into your classpath, you don't need to extract them. You can put the jar file as it is into your classpath.
If you want to put c:\myjava\lib\xxx.jar in your classpath, you have to give full path of the jar file like
set classpath=%classpath%;c:\myjava\lib\xxx.jar


Monty Fury

Joined: Jul 27, 2001
Posts: 1
I too have spent hours and hours trying to work out why,
despite setting my CLASSPATH correctly to point to
the servlet.jar archive in the Tomcat installation,
the javac compiler refuses to find it and thus gives
such messages as "package javax.servlet does not exist".
By searching on Sun's java sites, the Tomcat site, and
many mailing lists, I saw that tons of people were having
the same problem, and the only replies offered were of the
form "are you *sure* you've set the CLASSPATH properly?!"
Naturally, I was sure I had, but as it turns out, I hadn't:
There was a problem with case-sensitivity, at least on my
system (Windows ME). The servlet.jar file was located as
C:\Program Files\Tomcat-3.2.3\lib\servlet.jar
and I was setting CLASSPATH as follows:
(the ".;" bit placed at the start as recommended at
I was using DOS filenames because I *thought* that was the
safest thing to do whenever programs like Tomcat that involve
DOS are involved. But then I finally tried setting the path as:
and that solved the problem.
patrick regan

Joined: Sep 27, 2001
Posts: 1
I am trying to do the same thing with no luck. I have tried everything listed in this post and replys, and nothing is working for me. I have tomcat 4.0 installed in windows nt 4.0, which works fine when i go to http://localhost:8080. the servlets that are there operate properly, but i cannot compile them (or any others) without getting a package javax.servlet does not exist error every time. I have d:\j2sdkee1.3 set as J2EE_HOME, D:\JDK13~1.1_0 set as JAVA_HOME (although i have tried d:\jdk1.3.1_01 as well). my PATH includes %JAVA_HOME%\bin and %J2EE_HOME%\bin. I have tried my CLASSPATH with
.; ...
.;C:\PROGRA~1\APACHE~1.0\server\lib\servlet.jar; ... (as suggested above)
Why is nothing I am trying working, and even more important, why is this not properly documented on how to set this up? If anyone can help me, I would be extremely grateful.

Joined: Jul 12, 2006
Posts: 2
I've face the same problem and i have check servlet.jar and j2ee.jar
Both of these is inside my lib.
Below is my clsspath and path....
CLASSPATH --->%CLASSPATH%;C:\jakarta-tomcat-5.0.19\webapps\ROOT\WEB-INF\classes;
PATH ---> C:\Program Files\j2sdk_nb\j2sdk1.4.2

Could anybody help me...I'm new in this area..
Then 1 more qustion, after setting the environment could we have to restart our pc.
Lastly do we need to install J2EE Platform..


Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63838

"six nine",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

JavaRanch Sheriff

[Asking smart questions] [About Bear] [Books by Bear]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

You've also resurrected a very old thread.
Some of the information in this thread is outdated.
Please start a new thread with your question.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Package javax.servlet, javax.servlet.http does not exist
It's not a secret anymore!