严重: Servlet.service() for servlet [jsp] in context with path [/maven_test7] threw exception [Unable

严重: Servlet.service() for servlet [jsp] in context with path [/maven_test7] threw exception [Unable to compile class for JSP:

错误:
Maven 打开运行tomcat ,点击 首页jsp时报错:
严重: Servlet.service() for servlet [jsp] in context with path [/maven_test7] threw exception [Unable_第1张图片

严重: Servlet.service() for servlet [jsp] in context with path [/maven_test7] threw exception [Unable to compile class for JSP:

An error occurred at line: [31] in the generated java file: [H:\javashiyan\IDEA\HeiMa_Project_20201214\maven_test7\target\tomcat\work\Tomcat\localhost\maven_test7\org\apache\jsp\index_jsp.java]
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

Stacktrace:] with root cause
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [31] in the generated java file: [H:\javashiyan\IDEA\HeiMa_Project_20201214\maven_test7\target\tomcat\work\Tomcat\localhost\maven_test7\org\apache\jsp\index_jsp.java]
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol A b s t r a c t C o n n e c t i o n H a n d l e r . p r o c e s s ( A b s t r a c t P r o t o c o l . j a v a : 589 ) a t o r g . a p a c h e . t o m c a t . u t i l . n e t . J I o E n d p o i n t AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint AbstractConnectionHandler.process(AbstractProtocol.java:589)atorg.apache.tomcat.util.net.JIoEndpointSocketProcessor.run(JIoEndpoint.java:312)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)


原因:

严重: Servlet.service() for servlet [jsp] in context with path [/maven_test7] threw exception [Unable_第2张图片

    <dependency>
      <groupId>javax.servlet.jspgroupId>
      <artifactId>jsp-apiartifactId>
      <version>2.0version>

    dependency>

看着黑马视频教程写代码时,教程中在pom.xml 中添加了以上代码,为了防止MyServlet.java 文件报错。但是tomcat 启动时,也会进行相应检索,检索到图上代码,会和Maven 内置的 tomcat 中的jar 包起冲突,从而报错。


解决办法:

调用范围约束 provided, 从而只在代码编译的时候调用上述代码块;运行的时候时候,就不会调用上上述代码块,最后不会再和内置tomacat 的 jar 包起冲突。

最终代码:

    <dependency>
      <groupId>javax.servlet.jspgroupId>
      <artifactId>jsp-apiartifactId>
      <version>2.0version>
      <scope>providedscope>
    dependency>

正常运行结果:

严重: Servlet.service() for servlet [jsp] in context with path [/maven_test7] threw exception [Unable_第3张图片

严重: Servlet.service() for servlet [jsp] in context with path [/maven_test7] threw exception [Unable_第4张图片

你可能感兴趣的:(黑马教程,java)