使用Tomcat 9时出现Jasper异常

时间:2018-01-05 14:47:21

标签: java jsp tomcat exception

我的任务是将网站从一个机构迁移到另一个机构。作为流程的一部分,我们尝试更新网站使用的版本。

最初我被要求使用Java 8和Tomcat 5.5(在Linux上),这导致了问题。此后我尝试使用Java 8将Web应用程序部署到Tomcat 9.部分Web应用程序似乎运行良好(并解决了我使用Tomcat5时遇到的问题)。但是,当我转到index.jsp时,主app会抛出JasperException - 部署到Tomcat 5.5的同一个Web应用程序没有问题。

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

An error occurred at line: [15] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
The type index_jsp must implement the inherited abstract method JspSourceImports.getPackageImports()

An error occurred at line: [15] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
The type index_jsp must implement the inherited abstract method JspSourceImports.getClassImports()

An error occurred at line: [15] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
The type index_jsp must implement the inherited abstract method JspSourceDependent.getDependants()

An error occurred at line: [22] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
The type Map is not generic; it cannot be parameterized with arguments <String, Long>

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

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

An error occurred at line: [29] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
_jspx_imports_packages cannot be resolved to a variable

An error occurred at line: [29] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
The type HashSet is not generic; it cannot be parameterized with arguments <>

An error occurred at line: [30] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
_jspx_imports_packages cannot be resolved

An error occurred at line: [31] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
_jspx_imports_packages cannot be resolved

An error occurred at line: [32] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
_jspx_imports_packages cannot be resolved

An error occurred at line: [33] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
_jspx_imports_classes cannot be resolved to a variable

An error occurred at line: [39] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
The type Map is not generic; it cannot be parameterized with arguments <String, Long>

An error occurred at line: [40] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
_jspx_dependants cannot be resolved to a variable

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

An error occurred at line: [44] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
_jspx_imports_packages cannot be resolved to a variable

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

An error occurred at line: [48] in the generated java file: [/opt/tomcat9/work/Catalina/localhost/home/org/apache/jsp/index_jsp.java]
_jspx_imports_classes cannot be resolved to a variable

Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:213)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:458)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:389)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:361)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    edu.purdue.cybercenter.ionomics.servlet.PiiMS.doGet(PiiMS.java:83)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

我发现的大多数类似问题都表明这与jar文件有关,可能还有某种冲突。但是,tomcat 9的lib结构与tomcat5不同,我不确定哪个jar可能导致这种情况。我还尝试将index.jsp更改为更简单的(HelloWorld)表单 - 删除任何代码,抛出相同的异常。

是否有人遇到类似问题和/或有任何建议?

感谢。

1 个答案:

答案 0 :(得分:0)

在这种特殊情况下,问题是应用程序WEB-INF/lib目录中的许多库确实需要删除,包括:

  • rt.jar
  • servlet-api.jar

我正在回答这个问题建议将其关闭,因为这是一个“简单的错误”,但有些读者可能会发现查看分辨率实际上是有用的。