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?

Recommended Answers

All 5 Replies

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?

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.

I found the jar file with the packages. Problem solved.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.