How to Solve Servlet Errors in Eclipse?


Servlet Errors in Eclipse

For new users, it’s common to encounter following errors while developing servlet in Eclipse (I am using eclipse-jee-indigo-SR2-win32) or without it:

HttpServlet cannot be resolved to a type
HttpServletRequest cannot be resolved to a type
HttpServletResponse cannot be resolved to a type
ServletException cannot be resolved to a type
The import javax.servlet cannot be resolved
WebServlet cannot be resolved to a type

servlet-api.jar errors in eclipse
servlet-api.jar errors in eclipse

Java – Download Free EBooks and Whitepapers

The problem is “servlet-api.jar” is not on classpath.

How to add servlet-api.jar in classpath from Eclipse?

Right Click on the Web Project and Click on Properties

Dynamic Web Project Properties in Eclipse
Dynamic Web Project Properties in Eclipse

Select Java Build Path

Java Build Path in Eclipse
Java Build Path in Eclipse

Click on the Library Tab

Java Build Path in Eclipse-Libraries
Java Build Path in Eclipse-Libraries

Click on “Add External Jar” -> Locate servlet-api.jar from your local system (It’s available in Tomcat Distribution directory.)

Add External Jar servlet-api.jar from tomcat installation dir
Add External Jar servlet-api.jar from tomcat installation dir
servlet-api.jar external jar added
servlet-api.jar external jar added

Click OK and all errors will be resolved.

Servlet errors resolved
Servlet errors resolved

Done!!!

Other Interesting Tomcat related Articles:

Advertisements

13 thoughts on “How to Solve Servlet Errors in Eclipse?”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s