org.apache.jasper.JasperException: Unable to compile class for JSP
Posted zeroingToOne
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了org.apache.jasper.JasperException: Unable to compile class for JSP相关的知识,希望对你有一定的参考价值。
在controller中跳转到.jsp文件时报错:Unable to compile class for JSP
严重: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: [14] in the generated java file: [C:\\Users\\Admin\\workspace\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\work\\Catalina\\localhost\\SpringDemo\\org\\apache\\jsp\\WEB_002dINF\\contents\\front\\news_jsp.java] Only a type can be imported. view.News resolves to a package Stacktrace: at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103) at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366) at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:490) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:379) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:354) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:341) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1282) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) javax.servlet.http.HttpServlet.service(HttpServlet.java:624) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.78 logs.
网上找的原因大多是
1. jdk和Tomcat版本不对应
2. javax.servlet.jar 和 javax.servlet.jsp.jar 等包重复
但之前的页面都能正常运行,只有这一个界面不能请求,猜想应该不是上述问题。然后发现.jsp文件没有被编译,如图,因此应该是jsp页面中有什么问题导致.jsp页面没有被编译。
后来受Stack Overflow的启发,这里说jsp中导入的.java文件时的格式问题,想到是不是自己.jsp引入了什么错误的文件,发现引入了一个不存在的.java文件:Domain.News.java,直接删了这个引用就好了。因为直接复制的之前的代码,忘了删除引用的文件
因为jsp本质是一个servlet。在第一次请求jsp时,jsp会被容器转译为Servlet源代码、自动编译为.class文件、载入.class文件,然后生成Servlet对象。
以上是关于org.apache.jasper.JasperException: Unable to compile class for JSP的主要内容,如果未能解决你的问题,请参考以下文章