欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

tomcat遇到的问题(一)Error instantiating servlet class[已解决]

程序员文章站 2022-03-08 10:18:32
...

==============================================================================================

HTTP Status 500 - Error instantiating servlet class Servlet.HelloServlet


type Exception report

message Error instantiating servlet class Servlet.HelloServlet

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error instantiating servlet class Servlet.HelloServlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
root cause

java.lang.ClassNotFoundException: Servlet.HelloServlet
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.42 logs.

Apache Tomcat/7.0.42

==================================================================================================

web.xml内容如下:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0"
  metadata-complete="true">
	
	<servlet>
		<!--Servlet的内部名称-->
		<servlet-name>HelloServlet</servlet-name>	
		<!--Servlet的类名 包名+简单类名-->
		<servlet-class>Servlet.HelloServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<!--Servlet的内部名称-->
		<servlet-name>HelloServlet</servlet-name>
		<!--Servlet的访问名称 /名称-->
		<url-pattern>/he</url-pattern>
	</servlet-mapping>
	
	
</web-app>

Servlet初始化错误,没有找到类。原因是放class文件时直接放在了classes里,创建一个与包名相同的文件夹放进去即可。

路径应为: /webapps/项目名/WEB-INF/classes/包名/class文件