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

1

4 Answers 4

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

1
  • 2
    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
    – BalusC
    Mar 20, 2012 at 5: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

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

1
  • annotations are in more places then java.lang. The OP is not trying to create their own annotation
    – Sean
    Mar 20, 2012 at 3:56
-2

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.