Why there is an error in import javax.servlet.*?
Solution 1
The servlet API is not a part of the JDK, you need to add an additional dependency to your pom.xml
.
If this is for a webapp you can add this dependency with provided
scope and the servlet container will make these classes available to your webapp at deployment time.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
Solution 2
javax.servlet.*
is part of the Servlet API (which is part of the Java EE framework). Web Application Server/Web Containers wishing to use Servlets must implement the Servlet API.
Tomcat has servlet-api.jar
which can be found under TOMCAT_HOME/lib
(in Tomcat 6 and higher).
Find one that's relevant to you based on the Web Application Server you're running.
Solution 3
You need servlet-api.jar
. Assuming you're using Eclipse, you'd add the jar to your build path by right-clicking the project → Properties → Java Build Path → Add External JARs...
If you're using Tomcat 5.5, the JAR is in $CATALINA_HOME/common/lib
.
If you're using Tomcat 6+, the JAR is in $CATALINA_HOME/lib
.
If you're using JBoss 5, the JAR is in$JBOSS_HOME/common/lib
.
Solution 4
javax.servlet
is only available with Java Enterprise Edition. Either use it, or acquire the necessary JAR files (I got them with Apache Tomcat).
Solution 5
Tomcat? You need the servlet-api.jar
present inside tomcat/lib
user496949
Updated on June 04, 2020Comments
-
user496949 almost 4 years
I am using JavaSE6 and Eclipse, there is an error in the line
import javax.servlet.*
It seems there is no jar for this import.
How to fix it? Install anything, use Eclipse EE or add some dependency in Maven?