Solution to 'Default superclass jakarta.servlet.http.HttpServlet not found'

If you encounter this issue in a Java web project, it indicates that the default superclass 'jakarta.servlet.http.HttpServlet' is not available on the Java build path, and there might be a mismatch in the dynamic web module facet version.

Possible Solution:

Follow these steps to resolve the problem:

  1. Check Dynamic Web Module Facet Version:
  2. Verify that the dynamic web module facet version in your project is set to version 5.0, as mentioned in the error message. Right-click on your project, navigate to 'Properties,' and then 'Project Facets.' Ensure that the 'Dynamic Web Module' facet is set to version 5.0.

  3. Update Servlet API Library:
  4. Make sure that your project includes the correct Servlet API library for version 5.0. If not, you may need to update or add the library. If you're using Maven, check your 'pom.xml' file for the correct servlet-api dependency.

  5. Check Java Build Path:
  6. Ensure that 'jakarta.servlet-api' or 'javax.servlet-api' is included in your project's Java Build Path. Right-click on your project, go to 'Properties,' and then 'Java Build Path.' In the 'Libraries' tab, add the Servlet API library.

  7. Update Project Configuration:
  8. If you are using an IDE like Eclipse, IntelliJ, or another, try refreshing or rebuilding the project. This ensures that the changes in facet version and library inclusion take effect.

  9. Rebuild and Restart:
  10. After making these changes, clean and rebuild your project. Restart your servlet container or application server to apply the changes.

By following these steps, you should be able to resolve the issue related to the default superclass 'jakarta.servlet.http.HttpServlet' not found.

If http.HttpServlet mostly means you do not have a Tomcat for the project, follow these steps:

Option 1:

  • Right-click on the project.
  • Select Properties.
  • Go to Project Facets.
  • Under Runtimes, make sure to checkmark the Tomcat option.
  • Click Apply.

If that does not work, you can try:

Option 2:

  • Right-click on the project.
  • Select Properties.
  • Go to Java Build Path.
  • Click on Add Library.
  • Choose Server Runtime, and select your Apache Tomcat 9.

To run javax.servlet with JSP, you need two dependencies:

First one is the Servlet API:


The second one is the JSP API:


Note: javax.servlet.jsp-api also includes the dependency to javax.servlet-api, so you do not need to include it explicitly in your project.

This means that javax.servlet-api is mandatory for JSP to work.

You can stick with the javax.naming rather than migrating to the new jakarta namespace. Eventually, you’ll want to make the migration to benefit from new and improved technologies, but it's not necessary this year or next.

Read the "Which version?" documentation page. You will see that versions 9.0.x and 10.0.x are functionally equivalent, developed in parallel. The only significant difference is the namespace change discussed above. So, use Tomcat 9 if you choose to stick with javax naming.

You’ll need to get your codebase in order to use only the javax naming. Apparently, you have some code that refers to the new jakarta naming. Fix that by checking your import statements and any use of fully-qualified class names. Utilize your IDE’s search tools for assistance.

By the way, if using Tomcat 9, you can change the dependency on the Servlet API from version 3.0.1 to version 4.0.3 of the Servlet specification. Refer to the "Which version?" page linked above, as well as the Jakarta EE site, to learn about the appropriate versions of specs for JSPs, etc.