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:
- Check Dynamic Web Module Facet Version:
- Update Servlet API Library:
- Check Java Build Path:
- Update Project Configuration:
- Rebuild and Restart:
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.
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.
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.
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.
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:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
The second one is the JSP API:
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
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.
Read Similar Articles
- How to Create Curved Lines Instead of Straight Lines in Chart.js?
- Entity Framework With Linq, inner Join, Group By, Order By Example
- How to Create Multilingual Website in Asp .Net
- [Fixed]-AttributeError: 'Engine' object has no attribute 'execute' when trying to run sqlalchemy in python to manage my SQL database
- [Solved]-"invariant violation: requirenativecomponent: ""rnsvgsvgview"" was not found in the uimanager."
- Toaster Power Consumption Calculator | What Is The Power Consumption Of a Toaster
- How To Edit/Delete Selected Row From HTML Table Using JavaScript
- Solved Error: Cannot Convert From String to NewtonSoft.Json.JsonReader
- [Solved]: How to update claims in ASP.NET Core