本文翻译自:The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path [duplicate]
This question already has an answer here: 这个问题在这里已有答案:
I have a project created by Maven integration in Eclipse. 我有一个由Eclipse中的Maven集成创建的项目。 All work fine, but in the work space in all JSP files have this: 一切正常,但在所有JSP文件的工作空间中都有这样的:
The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
To the first string where place: 到第一个字符串所在的位置:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
When I create a basic dynamic web project and JSP in - all is fine, no errors. 当我创建一个基本的动态Web项目和JSP时 - 一切都很好,没有错误。
#1楼
参考:https://stackoom.com/question/1XTuj/在Java-Build-Path中找不到超类-javax-servlet-http-HttpServlet-重复
#2楼
Include servlet-api-3.1.jar in your dependencies. 在依赖servlet-api-3.1.jar中包含servlet-api-3.1.jar 。
Maven Maven的
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency>Gradle 摇篮
configurations { provided } sourceSets { main { compileClasspath += configurations.provided } } dependencies { provided 'javax.servlet:javax.servlet-api:3.1.0' }
#3楼
Select project → Properties → Project Facets → Target Runtimes → VMware Server . 选择项目→ 属性 → 项目构面 → 目标运行时 → VMware服务器 。
It worked for me. 它对我有用。
#4楼
Project → Properties → Target Runtimes → Apache Tomcat worked for me. 项目→ 属性 → 目标运行时 → Apache Tomcat为我工作。 There is no Target Runtimes under Facets (I'm on Eclipse v4.2 (Juno)). Facets下没有Target Runtimes(我在Eclipse v4.2 (Juno)上)。
#5楼
As this is unanswered, I am guessing something other than Maven dependencies are wrong with the ops build. 由于这是没有答案的,我猜测除了Maven依赖项之外的其他东西是ops构建错误的。
While not using Maven, I have the same problem from time to time when re-creating my development environment from svn, and I always forget why and have to figure it out. 虽然不使用Maven,但是当我从svn重新创建我的开发环境时,我经常会遇到同样的问题,而且我总是忘记原因并且必须弄明白。 Unfortunately it seems this is a problem with Eclipse. 不幸的是,这似乎是Eclipse的一个问题。
I am able to remove all such errors from once working projects by picking just one of the dynamic web projects, or just tomcat dependent projects, and move a dependency in the build order. 我可以通过选择一个动态Web项目或仅仅依赖于tomcat的项目从一次工作项目中删除所有此类错误,并在构建顺序中移动依赖项。 This seems to force all projects to rebuild properly and all of the errors are then resolved. 这似乎迫使所有项目正确重建,然后解决所有错误。
Right click on a web project, select "build Path" -> "Configure Build Path". 右键单击Web项目,选择“构建路径” - >“配置构建路径”。 Go to the tab "Order and Export", then pick a library or jar entry and move it up or down. 转到“订购和导出”选项卡,然后选择库或罐子条目并向上或向下移动。 I used the JRE System Library and moved it to the top. 我使用了JRE系统库并将其移到了顶部。
Click OK, and all that red goes away! 单击确定,所有红色消失!
#6楼
如果您没有使用Maven,只需将javax.servlet-api.jar放在项目lib文件夹中即可。
在Eclipse中,Maven项目出现错误提示“在Java Build Path中找不到超类'javax.servlet.http.HttpServlet'”。解决方案包括检查Maven依赖、设置目标运行时(如Apache Tomcat或VMware Server)、调整构建顺序,或直接将javax.servlet-api.jar添加到项目库中。

125

被折叠的 条评论
为什么被折叠?



