W3docs

The import javax.servlet can't be resolved

If you are getting the error "The import javax.servlet can't be resolved", it means that the javax.servlet package is not available on the classpath.

If you are getting the error "The import javax.servlet can't be resolved", it means that the javax.servlet package is not available on the classpath.

To fix this error, you need to include the servlet API in your project's classpath. This is typically provided by the Java web container (e.g., Tomcat or Jetty) that you are using.

If you are using an Integrated Development Environment (IDE) such as Eclipse or IntelliJ IDEA, you can add the servlet API by configuring your server runtime:

  1. In your IDE, open your project's run/debug configuration or server settings.
  2. Add a Tomcat or Jetty server runtime to your project.
  3. The IDE will automatically include the servlet API on the classpath, resolving the import error.

Alternatively, if you are using Maven as your build tool, you can include the javax.servlet dependency in your pom.xml file:


<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>4.0.1</version>
  <scope>provided</scope>
</dependency>

I hope this helps. Let me know if you have any questions.