javax.servlet.jsp.PageContext cannot be resolved to a type [duplicate]

You will need to import in your project the JSP APIs, which are not included in servlet-api

In my project, the solution is:

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

The solution that worked for me, is given in this answer. Go to project properties > Targeted runtimes > Select the checkbox for a runtime (Apache Tomcat 7 in my case).
That's all. Just build the project now and everything will be fine.


Assuming this is the pom for a web application...

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
</dependency>

A number of these dependencies should be set as provided as they are provisioned by the container. You should not bundle these with your application. See Maven dependency scopes. Failure to do this may result in undefined behaviour.

Exactly which dependencies are provided depends on the container.