导入 javax.servlet.annotation 无法解析

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9781070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 07:35:44  来源:igfitidea点击:

The import javax.servlet.annotation cannot be resolved

javaeclipsetomcatservletsjar

提问by chinna_82

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

我试图为我的项目创建 servlet,但遇到了The import javax.servlet.annotation cannot be resolved. 我已经从 tomcat添加了javax.servletservlet-api.jar。请参考下图。 小服务程序

采纳答案by Sean

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

通过屏幕截图,您似乎正在导入 servlet 规范 v2.5。servlet 注释是在 servlet 规范 3.0 中添加的

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

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

您将希望获得更新版本的 jar,然后是您当前使用的版本

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

这是一个图表,显示了 Tomcat 版本和它支持的 servlet 规范 http://tomcat.apache.org/whichversion.html

回答by kandarp

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

注释不在 javax.servlet 包中。它在 java.lang.annotation.* 下

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

请参考以下链接.. http://docs.oracle.com/javase/tutorial/java/javaOO/annotations.html

回答by Abhinai

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

只需在 buildpath servlet-api.jar 文件中导入版本大于 3.0 的包

回答by user2886971

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

确保您从链接http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/3.0.1下载 jar javax.servlet-api-3.0.1.jar