I'm trying to learn Java Servlets on my own but I'm having some very basic problems.

The code

"import javax.servlet.ServletException;"

produces a compiler error, "the import javax.servlet cannot be resolved".

I'm using version 3.2.2. Why am I having this problem?

8 Years
Discussion Span
Last Post by varun.x.anand

Nope by default the Java Plugin for Eclipse only includes Core Java, Servlets are not a part of that.
A short cut to resolve that error would be, in case you have tomcat / some other java enabled server installed, just check in their "lib" folder if you find any jar called "servlet.jar" or "j2ee.jar" or something similar in name and add it to your project's build path in Eclipse, this should solve the compile error.

However you will not be able to test your servlets directly via Eclipse in this case


I'm using Tomcat 5.0.

There are multiple lib folders and none of the jar files match exactly. Which folder should I look into? Even if I choose the right folder how exactly should I add it the built path? I attached the search result of "lib".

What is the other method of installing the servlet package?

Attachments searcheresults.JPG 147.96 KB

if you are using the latest version of tomcat 6.0+ there is a "lib" folder in the ROOT directory of tomcat, you should find the servlet.jar file there.
In tomcat 5.0 I assume it should be in $CATALINA_HOME/share/lib The second way is to install the J2EE Standard Tools plugin for eclipse.


javax.servlet.* package is not included in Eclipse. It is present in Tomcat 6.0/lib folder as servlet-api.jar and jsp-api.jar.
These two files can be imported to Eclipse by right clicking on your project's name in the Eclipse's Explorer window and selecting properties option from the popup menu. Then select Libraries tab from Java Build Path and then click Add External Jar option. Browse to the Tomcat installation folder and then select lib folder. Choose file servlet-api.jar and click finish.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.