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

今天使用 Eclipse+Maven 建立了一个 Javaweb 工程,并在 eclipse 中配置了 Web 容器 Jboss eap 6.2。新建 jsp 页面,添加一个简单

的 Java 类。可是,JSP 页面顶端出现“红色”的报错信息:The superclass "javax.servlet.http.HttpServlet" was not

found on the Java Build Path。原来 Javaweb 工程类中没有添加 Web 容器 Runtime 相关类导致。

错误提示:


 
解决方法很简单,在 pom.xml 中添加如下配置即可:

1 <dependency>
2 <groupId>javax.servlet</groupId>
3 <artifactId>servlet-api</artifactId>
4 <version>2.5</version>
5 <scope>provided</scope>
6 </dependency>

 

补充:如果还提示错误,还可以尝试下面的方式:

1、右击 web 工程 -》属性或 Build Path-》Java Build Path->Libraries-> Add Libray...->Server Runtime -》JBoss 7.1 Runtime


 
2、切换到 Java Build Path 界面中的 Orader and Export,选择