The import javax.servlet.annotation cannot be resolved
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
chinna_82
Updated on July 05, 2022Comments
-
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 addedjavax.servlet
andservlet-api.jar
from tomcat. Please refer the image below. -
Sean about 12 yearsannotations are in more places then java.lang. The OP is not trying to create their own annotation
-
BalusC about 12 yearsIn other words, you need Tomcat 7.0 with a
web.xml
declared conform Servlet 3.0. Otherwise just live with<servlet>
stuff inweb.xml
. See also stackoverflow.com/tags/servlets/info