Unable to compile class for JSP

错误背景:

项目原本运行在tomcat6底下,因某些原因需要升级到tomcat7,于是在部署完成tomcat7.0.69之后,把原tomcat6底下的war包拷贝到tomcat7底下的webapps目录下,关闭tomcat6,启动tomcat7,启动过程无报错.打开浏览器,访问项目首页,报无法解析jsp的错误.以下为此次错误的解决之道:

STEP1:

先来个错误日志(注意红色字体):

严重:Servlet.service()forservlet[jsp]incontextwithpath[/我是项目名称]threwexception[UnabletocompileclassforJSP]withrootcause

java.lang.IllegalArgumentException:Pagedirective:invalidvalueforimportatorg.apache.jasper.compiler.Node$PageDirective.validateImport(Node.java:628)

atorg.apache.jasper.compiler.Node$PageDirective.addImport(Node.java:609)

atorg.apache.jasper.compiler.Parser.parsePageDirective(Parser.java:352)

atorg.apache.jasper.compiler.Parser.parseDirective(Parser.java:473)

atorg.apache.jasper.compiler.Parser.parseFileDirectives(Parser.java:1773)

atorg.apache.jasper.compiler.Parser.parse(Parser.java:135)

atorg.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)

atorg.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:119)

atorg.apache.jasper.compiler.Compiler.generateJava(Compiler.java:194)

atorg.apache.jasper.compiler.Compiler.compile(Compiler.java:374)

atorg.apache.jasper.compiler.Compiler.compile(Compiler.java:354)

atorg.apache.jasper.compiler.Compiler.compile(Compiler.java:341)

atorg.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:662)

atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:364)

atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)

atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)

atjavax.servlet.http.HttpServlet.service(HttpServlet.java:731)

atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

atcom.ts.security.filter.RequestMethodFilter.doFilter(RequestMethodFilter.java:49)

atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

atcom.ts.security.filter.SecurityFilter.doFilter(SecurityFilter.java:71)

atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

atcom.ts.security.filter.RequestHeadFilter.doFilter(RequestHeadFilter.java:55)

atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

atcom.travelsky.pss.abframe.filter.LogFilter.doFilter(LogFilter.java:94)

atorg.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)

atorg.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)

atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

atorg.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)

atorg.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)

atorg.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)

atorg.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)

atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

atorg.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)

atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)

atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)

atorg.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)

atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)

atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

atorg.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)

atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)

atorg.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)

atorg.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)

atorg.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)

atjava.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

atorg.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

atjava.lang.Thread.run(Thread.java:619)

STEP2:

看step1的错误日志里面红色字体部分,他们是这个错误日志的关键部分。第一步,怀疑是不是tomcat7并没有部署成功,但它在没有部署项目上去的时候成功启动过,所以怀疑不成立;第二步,怀疑jar包冲突,项目的某些jar包,如servlet-api.jar等于tomcat本身的jar冲突,很快也排除此猜测,因为tomcat它优先加载的是项目路径底下的jar,找不到才加载其本身的jar包;其实事情发展到现在已经无头绪了,惟有继续BD搜索,万幸,找到一个有遇到同样问题的博主,原来是页面的pageimport标签搞得鬼..先看原来的<%@pageimport="java.lang.Exception;"%>,看到Exception后面那个分号(;)了吗,尼玛,就是它,删除它就好,tomcat7不认它...

该怎么说呢,理论上,按照jsp编写规范,这个分号的确是不该存在的,可是程序员习惯写完一段代码就会顺手加上个分号...anyway,坑爹就是了

相关推荐