爬坑记(7) :HTTP Status 500 - Unable to compile class for JSP

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35830949/article/details/80696984

简述

开发使用tomcat7进行测试,maven项目。服务器上tomcat8,部署上服务器启动ok,访问就报错。

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: 

An error occurred at line: [71] in the generated java file: [/usr/local/apache-tomcat-8.0.22/work/Catalina/localhost/Session/org/apache/jsp/jsp/index_jsp.java]
The method getDispatcherType() is undefined for the type HttpServletRequest

Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:198)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:450)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:361)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:580)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:356)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    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:1228)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

通过网上查找发现,这是tomcat8才会出错,因为tomcat8没有处理好容器和应用jar包冲突的问题。但是当配置了servlet-api.jar之后,就可能会与tomcat容器中的jar包冲突,导致出现以上问题,无法找到jsp,该问题在tomcat8即以上才会出现,在tomcat7即以下是没有问题的。

解决

  • 1.把tomcat8 lib下的这个servlet-api.jar干掉。
  • 2.把maven的依赖设置包不参与打包。添加scope限制为provided。(一劳永逸)
    实际情况:先把依赖排除掉(依赖少的化可以一个个点开查找,多的话可以使用idea依赖树进行筛选排除),在引入,不然会包编译错误,然后设置依赖范围。
<dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>jstl-api</artifactId>
            <version>1.2</version>
            <!-- 排除掉主动添加OK设置级别scope -->
            <exclusions>
                <exclusion>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <!-- 打包不参与,防止tomcat8自带serlet-api冲突  -->
          <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

疯了! HTTP Status 500 - org.apache.jasper.JasperException: Unable to compile class for JSP

05-24

tomcat(4.1.24-LE-jdk14)能启动,rnhttp://localhost:8080/MyApp/login.jsp是出现以下页面错误信息。rn应用是struts结构。rn由于重装了机器,装了win2003,好不容易把tomcat起来了。rnrnHTTP Status 500 - rnrn--------------------------------------------------------------------------------rnrntype Exception reportrnrnmessage rnrndescription The server encountered an internal error () that prevented it from fulfilling this request.rnrnexception rnrnorg.apache.jasper.JasperException: Unable to compile class for JSPrnrnAn error occurred at line: -1 in the jsp file: nullrnrnGenerated servlet error:rn [javac] Since fork is true, ignoring compiler setting.rn [javac] Compiling 1 source filern [javac] Since fork is true, ignoring compiler setting.rn [javac] javac: invalid flag: D:\Tomcatrn [javac] Usage: javac rn [javac] where possible options include:rn [javac] -g Generate all debugging inforn [javac] -g:none Generate no debugging inforn [javac] -g:lines,vars,source Generate only some debugging inforn [javac] -nowarn Generate no warningsrn [javac] -verbose Output messages about what the compiler is doingrn [javac] -deprecation Output source locations where deprecated APIs are usedrn [javac] -classpath Specify where to find user class filesrn [javac] -sourcepath Specify where to find input source filesrn [javac] -bootclasspath Override location of bootstrap class filesrn [javac] -extdirs Override location of installed extensionsrn [javac] -d Specify where to place generated class filesrn [javac] -encoding Specify character encoding used by source filesrn [javac] -source Provide source compatibility with specified releasern [javac] -target Generate class files for specific VM versionrn [javac] -help Print a synopsis of standard optionsrnrnrnrnrn at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)rn at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)rn at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:353)rn at org.apache.jasper.compiler.Compiler.compile(Compiler.java:370)rn at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)rn at com.nes.psmis.framework.filter.GbkFilter.doFilter(GbkFilter.java:32)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)rn at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)rn at java.lang.Thread.run(Thread.java:534)rnrnrnrn--------------------------------------------------------------------------------rnrnApache Tomcat/4.1.24-LE-jdk14

KindEditor上传文件出错,HTTP Status 500 - Unable to compile class for JSP:

12-16

有没有人在使用KindEditor的上传功能时遇到下面这样的问题。rnHTTP Status 500 - Unable to compile class for JSP:rnrntype Exception reportrnrnmessage Unable to compile class for JSP:rnrndescription The server encountered an internal error that prevented it from fulfilling this request.rnrnexceptionrnrnorg.apache.jasper.JasperException: Unable to compile class for JSP: rnrnAn error occurred at line: 124 in the jsp file: /editor_plugins/[color=red]jsp/upload_json.jsp[/color]rnJSONObject cannot be resolved to a typern121: %>rn122: <%!rn123: private String getError(String message) rn124: JSONObject obj = new JSONObject();rn125: obj.put("error", 1);rn126: obj.put("message", message);rn127: return obj.toJSONString();rnrnrnAn error occurred at line: 124 in the jsp file: /editor_plugins/jsp/upload_json.jsprnJSONObject cannot be resolved to a typern121: %>rn122: <%!rn123: private String getError(String message) rn124: JSONObject obj = new JSONObject();rn125: obj.put("error", 1);rn126: obj.put("message", message);rn127: return obj.toJSONString();rnrnrnAn error occurred at line: 39 in the jsp file: /editor_plugins/jsp/upload_json.jsprnServletFileUpload cannot be resolvedrn36: rn37: response.setContentType("text/html; charset=UTF-8");rn38: rn39: if (!ServletFileUpload.isMultipartContent(request)) rn40: out.println(getError("乱码。。。"));rn41: return;rn42: rnrnrnAn error occurred at line: 79 in the jsp file: /editor_plugins/jsp/upload_json.jsprnFileItemFactory cannot be resolved to a typern76: dirFile.mkdirs();rn77: rn78: rn79: FileItemFactory factory = new DiskFileItemFactory();rn80: ServletFileUpload upload = new ServletFileUpload(factory);rn81: upload.setHeaderEncoding("UTF-8");rn82: List items = upload.parseRequest(request);rnrnrnAn error occurred at line: 79 in the jsp file: /editor_plugins/jsp/upload_json.jsprnDiskFileItemFactory cannot be resolved to a typern76: dirFile.mkdirs();rn77: rn78: rn79: FileItemFactory factory = new DiskFileItemFactory();rn80: ServletFileUpload upload = new ServletFileUpload(factory);rn81: upload.setHeaderEncoding("UTF-8");rn82: List items = upload.parseRequest(request);rnrnrnAn error occurred at line: 80 in the jsp file: /editor_plugins/jsp/upload_json.jsprnServletFileUpload cannot be resolved to a typern77: rn78: rn79: FileItemFactory factory = new DiskFileItemFactory();rn80: ServletFileUpload upload = new ServletFileUpload(factory);rn81: upload.setHeaderEncoding("UTF-8");rn82: List items = upload.parseRequest(request);rn83: Iterator itr = items.iterator();rnrnrnAn error occurred at line: 80 in the jsp file: /editor_plugins/jsp/upload_json.jsprnServletFileUpload cannot be resolved to a typern77: rn78: rn79: FileItemFactory factory = new DiskFileItemFactory();rn80: ServletFileUpload upload = new ServletFileUpload(factory);rn81: upload.setHeaderEncoding("UTF-8");rn82: List items = upload.parseRequest(request);rn83: Iterator itr = items.iterator();rnrnrnAn error occurred at line: 85 in the jsp file: /editor_plugins/jsp/upload_json.jsprnFileItem cannot be resolved to a typern82: List items = upload.parseRequest(request);rn83: Iterator itr = items.iterator();rn84: while (itr.hasNext()) rn85: FileItem item = (FileItem) itr.next();rn86: String fileName = item.getName();rn87: long fileSize = item.getSize();rn88: if (!item.isFormField()) rnrnrnAn error occurred at line: 85 in the jsp file: /editor_plugins/jsp/upload_json.jsprnFileItem cannot be resolved to a typern82: List items = upload.parseRequest(request);rn83: Iterator itr = items.iterator();rn84: while (itr.hasNext()) rn85: FileItem item = (FileItem) itr.next();rn86: String fileName = item.getName();rn87: long fileSize = item.getSize();rn88: if (!item.isFormField()) rnrnrnAn error occurred at line: 115 in the jsp file: /editor_plugins/jsp/upload_json.jsprnJSONObject cannot be resolved to a typern112: return;rn113: rn114: rn115: JSONObject obj = new JSONObject();rn116: obj.put("error", 0);rn117: obj.put("url", saveUrl + newFileName);rn118: out.println(obj.toJSONString());rnrnrnAn error occurred at line: 115 in the jsp file: /editor_plugins/jsp/upload_json.jsprnJSONObject cannot be resolved to a typern112: return;rn113: rn114: rn115: JSONObject obj = new JSONObject();rn116: obj.put("error", 0);rn117: obj.put("url", saveUrl + newFileName);rn118: out.println(obj.toJSONString());rnrnrnStacktrace:rn org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)rn org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)rn org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)rn org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)rn org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)rn org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)rn org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:728)rn org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)rnnote The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.rnrnApache Tomcat/7.0.47rn[img=http://img.bbs.csdn.net/upload/201312/16/1387194365_271206.jpg][/img]

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭