Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there is an error in import javax.servlet.*?

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?

like image 375
user496949 Avatar asked Mar 06 '11 23:03

user496949


2 Answers

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>
like image 54
Martin Avatar answered Sep 28 '22 02:09

Martin


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.

like image 28
Buhake Sindi Avatar answered Sep 28 '22 02:09

Buhake Sindi