12

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

chinna_82
  • 6,353
  • 17
  • 79
  • 134
  • 2
    Oh please no, don't manually fiddle with container specific libraries. http://stackoverflow.com/questions/4076601/how-do-i-import-the-javax-servlet-api-in-my-eclipse-project – BalusC Mar 20 '12 at 05:31

4 Answers4

14

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

Sean
  • 7,597
  • 1
  • 24
  • 26
  • 2
    In other words, you need Tomcat 7.0 with a `web.xml` declared conform Servlet 3.0. Otherwise just live with `` stuff in `web.xml`. See also http://stackoverflow.com/tags/servlets/info – BalusC Mar 20 '12 at 05:32
7

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

Bucket
  • 7,415
  • 9
  • 35
  • 45
user2886971
  • 71
  • 1
  • 1
0

annotation is not in javax.servlet package. It is under java.lang.annotation.*

Please refer below link.. http://docs.oracle.com/javase/tutorial/java/javaOO/annotations.html

kandarp
  • 4,979
  • 11
  • 34
  • 43
  • annotations are in more places then java.lang. The OP is not trying to create their own annotation – Sean Mar 20 '12 at 03:56
-2

just import a package in the buildpath servlet-api.jar file with a version greater than 3.0

Abhinai
  • 1,082
  • 2
  • 13
  • 20