Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)

I am using Eclipse IDE to develop applications and I have downloaded the Tomcat server and it is running. My problem is the compiler is throwing an error like this:

The import javax.servlet can't be resolved.

Can somebody help me with this?

2 Answers

0 votes
by (13.1k points)

You have to add the Servlet API to your classpath. In the Tomcat, this is in a JAR called servlet-api.jar in its lib folder. You can do this in two ways:

  1. Leave the JAR in the lib folder of Tomcat

Right-click your project, click on properties->Java Build path->Libraries tab->click Add External JARs->Browse for servlet-api.jar and select it->click OK to update the build path.

  1. Copy the JAR into your project

Right-click the project, click properties->Java Build Path->click ADD JARs->find servlet-api.jar in the project and select it->click Ok to update the build path.

Want to learn Java? Check out the Java course from Intellipaat.

0 votes
ago by (1.8k points)

The package javax.servlet is an essential part of the java servlet api by default which is not included in the standard java SE runtime library.To resolve this concern we have to add servlet API dependency into the Pom file of our project.

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

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...