eclipse上web项目提示 The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path

使用eclipse开发web项目时,出现 The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path错误,对应以下几种情况。

1、Tomcat的位置发生改变的情况:

在Eclipse中,Window-->preference --> servers --> runtime --> environments,先把所有的Tomcat全部删除,再通过Add添加新的Tomcat。如下图:

eclipse上web项目提示 The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path

2、Tomcat的位置没有发生改变,在新建立的项目中遇到该问题的情况:

右键项目名→Properties→Project Facets→Runtimes→勾选Tomcat→Apply。

eclipse上web项目提示 The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path

以上解决方案是基于photon版本的eclipse,其他版本的解决方法略微不同,但实质类似。