HttpServlet 无法解析为类型....这是 eclipse 中的错误吗?

发布于 2024-12-24 02:06:40 字数 302 浏览 0 评论 0原文

一切都很好,我能够运行这个 JSP 项目, 突然发生了一些事情,大部分我的所有 servlet 都出现了未解决的错误。

我知道这是因为无法找到特定的 JAR 文件进行编译..但我的“buildpath”很好,我没有做任何更改..

我陷入了这种情况。 ..

尝试

  1. 多次清理项目
  2. 删除并添加JRE库
  3. 删除并添加服务器(Tomcat 7.0.23)

Every thing was fine and i was able to run this JSP project,
suddenly some thing happened and mostly all my servlets getting unresolved error.

I know its because specific JAR file cant be found for compilation.. but my "buildpath" is fine and i didnt make any changes..

I am stuck in this situation...

Tried

  1. cleaned project many times
  2. removes and added JRE library
  3. removed and added server(Tomcat 7.0.23)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

み格子的夏天 2024-12-31 02:06:40

您必须将 Web 项目的运行时设置为您正在使用的 Tomcat 安装;您可以在项目配置的“目标运行时”部分中执行此操作。

通过这种方式,您将允许 Eclipse 将 Tomcat 的 Java EE Web Profile jar 添加到构建路径。

请记住,HttpServlet 类不在 JRE 中,但至少在 Enterprise Web Profile 中(例如 servlet 容器运行时 /lib 文件夹)。

You have to set the runtime for your web project to the Tomcat installation you are using; you can do it in the "Targeted runtimes" section of the project configuration.

In this way you will allow Eclipse to add Tomcat's Java EE Web Profile jars to the build path.

Remember that the HttpServlet class isn't in a JRE, but at least in an Enterprise Web Profile (e.g. a servlet container runtime /lib folder).

倾`听者〃 2024-12-31 02:06:40

这意味着 servlet jar 丢失。

检查您的项目的库。
配置您的构建路径下载 **

servlet-api.jar

** 并将其导入到您的项目中。

It means that servlet jar is missing .

check the libraries for your project.
Configure your buildpath download **

servlet-api.jar

** and import it in your project.

泪眸﹌ 2024-12-31 02:06:40

对我来说一个简单的解决方案是转到“属性”->“ Java 构建路径 ->订购并导出,然后检查 Apache Tomcat 库。这是假设您已经将 Tomcat 设置为部署目标并且仍然收到错误。

A simple solution for me was to go to Properties -> Java Build Path -> Order and Export, then check the Apache Tomcat library. This is assumes you've already set Tomcat as your deployment target and are still getting the error.

人生戏 2024-12-31 02:06:40

我也遇到过这种情况,原因是在 eclipse 中创建项目时选择了不合适的 tomcat 和动态 web 模块版本的组合。我选择了 Tomcat v9.0 以及动态 Web 模块版本 3.1,并且 eclipse 无法解析 HttpServlet 类型。当使用 Tomcat 7.0 和动态 Web 模块版本 7.0 时,Eclipse 能够自动解析 HttpServlet 类型。

相关问题 Dynamic Web Module option in Eclipse

要检查 tomcat 的版本应该是与不同版本的 Servlet 和 JSP 规范一起使用请参考 http://tomcat.apache.org/whichversion.html

It happened for me also and the reason was selecting inappropriate combination of tomcat and Dynamic web module version while creating project in eclipse. I selected Tomcat v9.0 along with Dynamic web module version 3.1 and eclipse was not able to resolve the HttpServlet type. When used Tomcat 7.0 along with Dynamic web module version 7.0, eclipse was automatically able to resolve the HttpServlet type.

Related question Dynamic Web Module option in Eclipse

To check which version of tomcat should be used along with different versions of the Servlet and JSP specifications refer http://tomcat.apache.org/whichversion.html

×纯※雪 2024-12-31 02:06:40

我在网上找到的所有建议都没有为我解决问题,甚至本次对话中的建议也没有解决。

唯一解决的办法是卸载 Tomcat 10 并安装版本 9,然后问题就消失了。我考虑到了这一点(http://tomcat.apache.org/whichversion.html) ,但这似乎与我的问题没有任何关系。

None of the recommendations I found on the web resolved for me, not even the ones here in this conversation.

The only thing that did resolve was uninstalling Tomcat 10 and installing version 9, then the issue was gone. I took this (http://tomcat.apache.org/whichversion.html) into account, but that didn't seem to have anything to do with my issue.

柳絮泡泡 2024-12-31 02:06:40

我在 eclipse 和 tomcat7 中遇到了同样的问题,错误 javax.servlet 无法解决。如果我在目标运行时模式下选择服务器并再次构建项目,错误就会得到解决。

I faced the same problem in eclipse with tomcat7 with the error javax.servlet cannot be resolved. If I select the server in targeted runtime mode and build project again, the error get's resolved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文