2020.4.5 使用tomcat插件启动javaweb报错:Servlet.service() for servlet in context with path threw exception

maven使用tomcat7-maven-plugin插件启动javaweb项目报错:
原因:Tomcat7自带了servlet和jsp的jar包,maven项目中同时也引入了自己本地库中的servlet和jsp的jar包,导致了jar包冲突

四月 05, 2020 12:25:39 下午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8080"]
四月 05, 2020 12:25:39 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Tomcat
四月 05, 2020 12:25:39 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.47
四月 05, 2020 12:25:40 下午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8080"]
四月 05, 2020 12:26:05 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [jsp] in context with path [] threw exception [Unable to compile class for JSP: 

An error occurred at line: [31] in the generated java file: [/Users/dzzhyk/Desktop/Java/program/loginExample/target/tomcat/work/Tomcat/localhost/_/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: [/Users/dzzhyk/Desktop/Java/program/loginExample/target/tomcat/work/Tomcat/localhost/_/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:366)
	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.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
	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:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

解决方案:
在dependency中的servlet和jsp的添加信息中加入:

<scope>providedscope>

让自己引入的jar包只在写代码的时候使用,而在运行时使用tomcat7插件自带的jar包
2020.4.5 使用tomcat插件启动javaweb报错:Servlet.service() for servlet in context with path threw exception_第1张图片
参考:
https://blog.csdn.net/qq_38408785/article/details/89494751

你可能感兴趣的:(总结)