The import javax.servlet.annotation cannot be resolved

34,170

Solution 1

By the screenshot it looks like you are importing servlet spec v2.5. The servlet annotations were added in servlet spec 3.0

http://docs.oracle.com/javaee/6/api/javax/servlet/annotation/package-summary.html

You will want to get the jar for a newer version then what you are currently using

Here is a chart showing the Tomcat version and the servlet spec it supports http://tomcat.apache.org/whichversion.html

Solution 2

Ensure You download the jar javax.servlet-api-3.0.1.jar from the link http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/3.0.1

Share:
34,170
chinna_82
Author by

chinna_82

Updated on July 05, 2022

Comments

  • chinna_82
    chinna_82 almost 2 years

    Im trying to create servlet for my project but encountered The import javax.servlet.annotation cannot be resolved. I've already added javax.servlet and servlet-api.jar from tomcat. Please refer the image below. Servlet

  • Sean
    Sean about 12 years
    annotations are in more places then java.lang. The OP is not trying to create their own annotation
  • BalusC
    BalusC about 12 years
    In other words, you need Tomcat 7.0 with a web.xml declared conform Servlet 3.0. Otherwise just live with <servlet> stuff in web.xml. See also stackoverflow.com/tags/servlets/info