The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path之二(示例代

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path之二(示例代相关的知识,希望对你有一定的参考价值。

这篇短文里有两种解决方案,另外一篇短文里还有第三种解决方案,查看请点击这里

1. 报错如图:

技术分享

这是错误提示:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path


 2. 错误分析:

本来想着是因为缺少web容器,也就是Servlet容器。

所以我在pom.xml文件里添加了tomcat插件:

 1 <plugins>
 2     <plugin>                        
 3         <groupId>org.apache.tomcat.maven</groupId>
 4         <artifactId>tomcat7-maven-plugin</artifactId>
 5         <version>2.2</version>
 6         <configuration>
 7         <port>8050</port>
 8         <path>/</path>
 9         </configuration>
10     </plugin>
11 </plugins>

但问题并没有解决,还是报一样的错。


 3.1 解决方案

 然后尝试着在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>
 7 <dependency>
 8     <groupId>javax.servlet</groupId>
 9     <artifactId>jsp-api</artifactId>
10     <version>2.0</version>
11     <scope>provided</scope>
12 </dependency>    

错误解决了。


 3.2 接着又尝试着删掉了pom.xml文件里的tomcat插件,工程依旧没有问题。

 接着又尝试着删掉了pom.xml文件里的servlet.api和jsp-api。

接着右击项目-->Build Path-->Add Libraries-->Server Runtime......

也可以解决问题,工程不报错。


 4. 分析 3.1、3.2 两个解决方案:

pom.xml文件里添加tomcat插件,并不会把servlet-api和jsp-api也依赖进来,所以还要手动依赖进来这两个jar包。

但通过右击项目-->Build Path-->Add Libraries-->Server Runtime......的方式添加 tomcat 的话会把 servlet API 和 jap API 也依赖进来。


5.还有第三种解决方案

请点击这里查看我的另外一篇短文。

以上是关于The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path之二(示例代的主要内容,如果未能解决你的问题,请参考以下文章

java web报错The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build

新建 jsp异常,The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build P

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

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

java错误:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Bu

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