Nilashish C
Nilashish C

Reputation: 459

Why am I getting "The import javax.servlet.http.HttpFilter cannot be resolved"?

I have a Maven project running on Tomcat 8.0.50. I was trying to place a filter before a Servlet to validate some form data. I tried to extend the HttpFilter Abstract Class as per this.

But Eclipse keeps on throwing this error:

"The import javax.servlet.http.HttpFilter cannot be resolved."

I can, however, import other classes in javax.servlet.* and javax.servlet.http.*

Also, I can implement the Filter interface.

Any help with this?

Upvotes: 1

Views: 1769

Answers (1)

miskender
miskender

Reputation: 7948

HttpFilter class is available with java-ee 8 (with servlet 4.0). Tomcat version 8.xxx is implementing Servlet 3.1. With tomcat version 9, Servlet 4.0 is implemented.

You can add java-ee 8 dependency and use HttpFilter class. (or switch to tomcat 9 and add scope provided dependency)

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>8.0</version>
</dependency>

http://tomcat.apache.org/whichversion.html

Upvotes: 5

Related Questions