The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

编程 · 2021-09-06 · 85 人浏览

原因:在 java web 工程下没有引入中间件(服务器 tomcat)运行的 library,一般只有动态网页工程才有这个报错

解决办法

(1): 确认 eclipse 中 server 的运行环境是否有配置,设置方法为:Window → Preferences → Server → Runtime Environments →Add → 选择 Apache 的版本后点 Next,再填入你 apache tomcat 软件的安装(解压后)目录。

(2): 右击 web 工程 → Build Path → Configure build path... → Java Build Path → Libraries → Add Libray... → Server Runtime →Next> → Apache Tomcat Server →Finish。

(3): 切换到 Java Build Path 界面中的 Orader and Export,勾选 Tomcat。

(4): 右击 web 工程 → 属性 → Project Facets → 点击右侧 tab 选择 Runtimes → 勾选 tomcat → OK。