我新建了一个JSP项目,遇到一个编译错误:The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
解决方法
新建Server Runtime Environment:
Runtime Environments选择Apache Tomcat:
右键单击JSP项目,Build Path->Configure Build Path:
Add Library->Server Runtime:
添加完毕后,Eclipse里的编译错误消失了:
查看JSP项目文件夹下的.classpath文件,格式为xml,我们之前维护的Apache Server runtime已经写入在里面了:
<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <attributes> <attribute name="module" value="true"/> <attribute name="owner.project.facets" value="java"/> </attributes> </classpathentry> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0"/> <classpathentry kind="output" path="build/classes"/> </classpath>