解决Jsp运行org.apache.jasper.JasperException: Unable to compile class for JSP:问题

初学Maven就遇到困难了!!!在b站跟着视频开始接触maven来创建一个webapp项目,在jsp跳转的时候遇到一个bug,身边也没大佬带,只能自己慢慢摸索,在Maven项目中出现了报org.apache.jasper.JasperException: Unable to compile class for JSP:的问题,在网上查了很多方法来尝试解决,但天资愚钝无法理解大佬的跳转思维,后面某论坛看到解决放方案。

链接:https://blog.csdn.net/u011781521/article/details/53713162

一、问题描述

 

eclipse通过maven插件创建一个WEB项目通过内嵌Tomcat加载项目,启动没问题,一访问页面就报错提示无法将jsp编译为class文件:

 

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 1 in the generated java file
The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

 

 技术图片

错误的原因为:tomcat6不支持jdk1.8版本

 

我pom.xml文件里明明配置的是Tomcat7啊!!  怎么是tomcat6运行去了。。。

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5   <modelVersion>4.0.0</modelVersion>
 6 
 7   <groupId>com.itheima</groupId>
 8   <artifactId>maven_java</artifactId>
 9   <version>1.0-SNAPSHOT</version>
10   <packaging>war</packaging>
11 
12   <name>maven_java Maven Webapp</name>
13   <!-- FIXME change it to the project‘s website -->
14   <url>http://www.example.com</url>
15 
16   <properties>
17     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18     <maven.compiler.source>1.7</maven.compiler.source>
19     <maven.compiler.target>1.7</maven.compiler.target>
20   </properties>
21 
22   <dependencies>
23     <dependency>
24       <groupId>junit</groupId>
25       <artifactId>junit</artifactId>
26       <version>4.11</version>
27       <scope>test</scope>
28     </dependency>
29 
30     <dependency>
31       <groupId>javax.servlet</groupId>
32       <artifactId>servlet-api</artifactId>
33       <version>2.5</version>
34       <scope>provided</scope>
35     </dependency>
36 
37     <!-- https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
38     <dependency>
39       <groupId>javax.servlet.jsp</groupId>
40       <artifactId>jsp-api</artifactId>
41       <version>2.1</version>
42       <scope>provided</scope>
43     </dependency>
44 
45   </dependencies>
46 
47   <build>
48     <finalName>maven_java</finalName>
49     <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
50       <plugins>
51         <plugin>
52           <artifactId>maven-clean-plugin</artifactId>
53           <version>3.1.0</version>
54         </plugin>
55         <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
56         <plugin>
57           <artifactId>maven-resources-plugin</artifactId>
58           <version>3.0.2</version>
59         </plugin>
60         <plugin>
61           <artifactId>maven-compiler-plugin</artifactId>
62           <version>3.8.0</version>
63         </plugin>
64         <plugin>
65           <artifactId>maven-surefire-plugin</artifactId>
66           <version>2.22.1</version>
67         </plugin>
68         <plugin>
69           <artifactId>maven-war-plugin</artifactId>
70           <version>3.2.2</version>
71         </plugin>
72         <plugin>
73           <artifactId>maven-install-plugin</artifactId>
74           <version>2.5.2</version>
75         </plugin>
76         <plugin>
77           <artifactId>maven-deploy-plugin</artifactId>
78           <version>2.8.2</version>
79         </plugin>
80         <plugin>
81           <groupId>org.apache.tomcat.maven</groupId>
82           <artifactId>tomcat7-maven-plugin</artifactId>
83           <version>2.2</version>
84         </plugin>
85       </plugins>
86     </pluginManagement>
87   </build>
88 </project>

 

 

注意: 如果你的版本是tomcat7-maven-plugin  2.0 的话,由于它不支持 jdk 1.8,所以把它换成 tomcat7-maven-plugin  2.2就行了。

 

二、解决方法

 

找了下发现原来是这里出了问题!!!

 

 技术图片

 

把它改为: tomcat7:run 就行了,就不会报错了

文章来自:https://www.cnblogs.com/junxiaobai/p/10915504.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3