If you are facing this error after importing an existing maven project into your eclipse IDE, then it means that http-servlet is not available in the project’s classpath and you must include it.
The error looks like this.
To include http-servlet into your classpath, you have two options.
1. Add Target Server Runtime
In this solution, you can add desired server runtime into your application as a project facet. As runtime servers have already servlet runtime dependencies, they get included in your project and hence the error is gone.
2. Add Maven Dependency
Another option is to include the latest version of javax.servlet-api dependency from Maven repository. This will also fix the error.
Do not forget to run
mvn update command after including the dependencies.
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.1</version> <scope>provided</scope> </dependency>
If you are using Jakarta servlet API, then you should be using the latest version of jakarta.servlet-api.
<dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>6.0.0</version> <scope>provided</scope> </dependency>
Happy Learning !!
Leave a Reply