How to fix the 'HttpServlet not found' error in Eclipse

When a developer builds their first Java web application with Tomcat and Eclipse, they may run into the “HttpServlet not found” exception in a JSP creation or Servlet addition to their web project. An error message right off the bat is enough to shake the confidence of even an experienced developer, but don’t fret because it’s a fixable problem.

The problem occurs because the newly created web project hasn’t yet been associated with the runtime libraries of your Java application server, be it Tomcat, Jetty, WebSphere or another option. It’s the Java application server that provides the various JAR and ZIP files that contain the Servlet and JSP APIs, which includes the problematic HttpServlet class. For this example, we will use Eclipse.

Here is how to fix the Eclipse error message HttpServlet not found in three steps:

1. Create a new server instance

If a developer hasn’t already created an application server instance within Eclipse, open the Server view of the Web Perspective and create a new server instance based on the Java application server locally installed. If a server instance already exists, that will suffice.

2. Associate the project and server instance

With the server instance created, right-click on the web project that contains the error and choose Run As –> Run on Server. In the wizard that appears, choose the server created in the first step.

3. Add the server runtime libraries

Right click on the web project and choose Properties.

In the window that appears, choose Java Build path on the left. Then choose the Libraries tab in the view that appears. Click the Add Runtime option and then select Server Runtime.

fix HttpServlet not found

Add the server runtime to the web project to fix the HttpServlet not found Eclipse error.

This will add all the JAR and ZIP files used by the servlet engine to the web project’s runtime path. When this step is complete, rebuild the project and the HttpServlet not found Eclipse error message will go away. A developer can then begin to develop a Java application.

App Architecture
Software Quality
Cloud Computing