JSP Tomcat 从 7.0.59 升级到 8.5.51 后出现编译异常

JSP compilation exception after Tomcat upgrade to 8.5.51 from 7.0.59

我已将 tomcat 版本从 7.0.59 升级到 8.5.51。升级后,我在尝试访问 index.jsp 页面时遇到异常。

SEVERE: Servlet.service() for servlet [jsp] threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [24] in the generated java file:
[/home/application_path/work/org/apache/jsp/index_005f_jsp.java]
The type index_005f_jsp must implement the inherited abstract method JspSourceImports.getPackageImports()

An error occurred at line: [24] in the generated java file:
[/home/application_path/work/org/apache/jsp/index_005f_jsp.java]
The type index_005f_jsp must implement the inherited abstract method JspSourceImports.getClassImports()

An error occurred at line: [38] in the generated java file:
[/home/application_path/work/org/apache/jsp/index_005f_jsp.java]
The type Set is not generic; it cannot be parameterized with arguments <String>

An error occurred at line: [40] in the generated java file:
[/home/application_path/work/org/apache/jsp/index_005f_jsp.java]
The type Set is not generic; it cannot be parameterized with arguments <String>

An error occurred at line: [43] in the generated java file:
[/home/application_path/work/org/apache/jsp/index_005f_jsp.java]
_jspx_imports_packages cannot be resolved to a variable

An error occurred at line: [44] in the generated java file:
[/home/application_path/work/org/apache/jsp/index_005f_jsp.java]
_jspx_imports_packages cannot be resolved

An error occurred at line: [64] in the generated java file:
[/home/application_path/work/org/apache/jsp/index_005f_jsp.java]
The type Set is not generic; it cannot be parameterized with arguments <String>

Stacktrace:
        at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
        at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:212)
        at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:552)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:381)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:351)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:597)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:399)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:470)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316)
        at ActiveServerPkg.ActiveServer.doPost2(ActiveServer.java:1004)
        at ActiveServerPkg.ActiveServer.doPost(ActiveServer.java:253)
        at ActiveServerPkg.ActiveServer.doGet(ActiveServer.java:245)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:609)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)

生成的 servlet 文件之间的差异

和tomcat7.0.59

public final class index_005f_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

和tomcat8.5.51

public final class index_005f_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent,
                 org.apache.jasper.runtime.JspSourceImports {

JspSourceImports 接口已添加到实现列表中

我认为这可能是由于 code/syntax 版本向后兼容性的变化,所以用简单的 Hello World 消息替换了我的 index.jsp 内容,但仍然面临同样的问题问题。

原始 JSP 内容由于组织政策问题无法共享,已修改 jsp 看起来像下面我可以重现此问题的地方。

<html>
<body>
    <h2>Hello World</h2>
</body>
</html>

java 使用的版本是 openjdk version 1.8.0_212

来自 tomcat lib 文件夹的 Jars...

我的 WEB-INF/lib 文件夹中可用的 jar 列表

activation.jar                                  jackson-annotations-2.10.2.ja   ribbon-2.7.17.jar             
antlr-complete-3.5.2.jar                        jackson-core-2.10.2.jar         ribbon-archaius-2.7.17.jar    
aopalliance-1.0.jar                             jackson-databind-2.10.2.jar     ribbon-core-2.7.17.jar        
apache.jar                                      jai_codec.jar                   ribbon-loadbalancer-2.7.17.jar
archaius-core-0.7.6.jar                         jai_core.jar                    ribbon-transport-2.7.17.jar
aspectj-maven-plugin-1.7.jar                    javassist-3.3.jar               security.jar
aspectjweaver-1.8.9.jar                         javax.batch-api-1.0.jar         servo-core-0.10.1.jar
avalon-framework-cvs-20020806.jar               javax.persistence-2.1.1.jar     servo-internal-0.10.1.jar
batik.jar                                       jboss-logging-3.3.0.Final.jar   slf4j-api-1.7.5.jar
bcprov-jdk16-145.jar                            jce1_2_2.jar                    slf4j-log4j12-1.6.6.jar
bsf-2.4.0.jar                                   jcert.jar                       smtp.jar
cglib-3.1.jar                                   jdbc.jar                        spring-aop-4.3.26.RELEASE.jar
commons-codec-1.10.jar                          jettison-1.3.7.jar              spring-aspects-4.3.26.RELEASE.jar
commons-collections-3.2.2.jar                   jnet.jar                        spring-batch-core-4.2.1.RELEASE.jar
commons-configuration-1.8.jar                   js.jar                          spring-batch-infrastructure-4.2.1.RELEASE.jar
commons-dbcp-1.3.jar                            jta-1.1.jar                     spring-beans-4.3.26.RELEASE.jar
commons-httpclient-3.1.SONATYPE.jar             local_policy.jar                spring-context-4.3.26.RELEASE.jar
commons-lang-2.4.jar                            log4j-1.2.17.jar                spring-context-support-4.3.26.RELEASE.jar
commons-logging-1.2.jar                         logback-classic-1.0.12.jar      spring-core-4.3.26.RELEASE.jar
commons-net-3.5.jar                             logback-core-1.0.12.jar         spring-expression-4.3.26.RELEASE.jar
commons-pool-1.5.4.jar                          mailapi.jar                     spring-jdbc-4.3.26.RELEASE.jar
cryptix-jce-api.jar                             mail.jar                        spring-orm-4.3.26.RELEASE.jar
cryptix-jce-compat.jar                          micrometer-core-1.1.5.jar       spring-oxm-4.3.26.RELEASE.jar
cryptix-jce-provider.jar                        mlibwrapper_jai.jar             spring-retry-1.1.2.RELEASE.jar
cryptix-message-api.jar                         mybatis-3.2.4.jar               spring-tx-4.3.26.RELEASE.jar
cryptix-openpgp-provider.jar                    mybatis-spring-1.2.2.jar        spring-web-4.3.26.RELEASE.jar
cryptix-pki-api.jar                             netflix-commons-util-0.1.1.jar  sunjce_provider.jar
dom4j-1.6.1.jar                                 netflix-statistics-0.1.1.jar    tag_gen.jar
fop.jar                                         ojdbc7.jar                      tomcat-jdbc-9.0.22.jar
guava-19.0.jar                                  ostermillerutils_1_07_00.jar    velocity-1.6.2.jar
hibernate-commons-annotations-4.0.4.Final.jar   poi-3.17.jar                    xalan200.jar
hibernate-core-4.3.10.Final.jar                 poi-ooxml-3.17.jar              xerces-2.4.0.jar
hibernate-ehcache-4.1.9.Final.jar               poi-ooxml-schemas-3.17.jar      xmlbeans-2.3.0.jar
hibernate-validator-4.3.0.Final.jar             pop3.jar                        xmlpull-1.1.3.1.jar
imap.jar                                        quartz-2.2.1.jar                XmlSchema-1.2.jar
j2ssh.jar                                       quartz-jobs-2.2.1.jar           xstream-1.4.11.1.jar

也清除了工作目录,但没有成功:(

也尝试了以下链接中的解决方案,但仍然无效。

JSP compilation fails with Tomcat 8.0.20. Works with 8.0.11

在这种特殊情况下,应用程序的 WEB-INF/lib 目录中的库 (jar) 之一导致了此问题,并且 jar 是...

cryptix-jce-compat.jar

从 lib 文件夹中删除 cryptix-jce-compat.jar 后,JSP 编译开始使用最新的 tomcat 版本(8.5.51 ) 因为它在较早的 tomcat 版本 (7.0.59).

中工作