我正在开发一个主要由jsp编写的Web应用程序。一切都运行良好,但突然当我尝试在服务器上运行项目(来自Eclipse)时,我在浏览器和eclipse中遇到以下两个错误:
HTTP Status 500 - Unable to compile class for JSP
type Exception report
message Unable to compile class for JSP
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
当我刷新浏览器时,我收到了不同的错误。
HTTP Status 500 - Unable to load class for JSP
type Exception report
message Unable to load class for JSP
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:598)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:137)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.ClassNotFoundException: org.apache.jsp.automation.actions.index_jsp
java.net.URLClassLoader$1.run(URLClassLoader.java:366)
java.net.URLClassLoader$1.run(URLClassLoader.java:355)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:354)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:133)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:65)
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:596)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:137)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我在许多地方读到错误是由于tomcat没有指向正确的jdk,我已经完成了。它指向Java 1.7。如果我指向1.8,则会出现The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
错误。
代码在早期工作正常,我不确定究竟发生了什么。我过去也有这个错误,我曾经重新导入项目等来解决它。这次我真的很想找到它的根源,因为这似乎偶尔会发生。我确信这是一些我缺少的配置,但我不确定是什么。
答案 0 :(得分:0)
首先检查此页面是否存在Tomcat VS Java版本兼容性:http://tomcat.apache.org/whichversion.html
如果您使用的是tomcat 8.x或7.x,则Java 7或8都可以。如果可以,请选择JDK8。
接下来,如果你想避免这种问题,请使用相同的jdk配置和重新编译你的eclipse项目(检查你的构建设置)。