Why is there a javax.servlet error in the import. *?

I use JavaSE6 and Eclipse, there is an error in the line

import javax.servlet.* 

There seems to be no jar for this import.

How to fix it? Install something, use Eclipse EE, or add some dependency to Maven?

+6
java eclipse maven maven-2
source share
5 answers

The servlet API is not part of the JDK, you need to add an extra dependency to your pom.xml .

If this is for webapp, you can add this dependency with the provided scope and the servlet container will make these classes available to your web application during deployment.

 <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> 
+10
source share

javax.servlet.* is part of the servlet API (which is part of the Java EE framework). Application web server / web containers wishing to use servlets must implement the servlet API.

Tomcat has servlet-api.jar , which can be found in TOMCAT_HOME/lib (in Tomcat 6 and later). Find the one that suits you based on the web application server you are using.

+4
source share

javax.servlet is only available in Java Enterprise Edition. Either use it, or purchase the necessary JAR files (I got them from Apache Tomcat ).

+2
source share

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 are using Tomcat 5.5 , the JAR is in $CATALINA_HOME/common/lib .

If you are using Tomcat 6+ , the JAR is in $CATALINA_HOME/lib .

If you are using JBoss 5 , the JAR is in $JBOSS_HOME/common/lib .

+2
source share

Tomcat? You need servlet-api.jar be present inside tomcat/lib

+1
source share

All Articles