gpt4 book ai didi

servlets - java.lang.ClassNotFoundException : HelloServlet at org. apache.catalina.loader.WebappClassLoader.loadClass

转载 作者:行者123 更新时间:2023-12-03 20:50:37 24 4
gpt4 key购买 nike

我在 webapps/hello/WEB-INF/class/HelloServlet.class 中有一个 Hello World servlet,我在 web.xml 中将其注册如下:

<servlet>
<servlet-name>helloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>

但是,Tomcat 启动失败,出现以下异常:

Apr 30, 2012 1:50:10 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet HelloServlet as unavailable
Apr 30, 2012 1:50:10 PM org.apache.catalina.core.ApplicationContext log
java.lang.ClassNotFoundException: HelloServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1128)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process
(Http11AprProtocol.java:594)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
at java.lang.Thread.run(Unknown Source)

Apr 30, 2012 1:50:10 PM org.apache.catalina.core.StandardWrapperValve invoke

这是怎么引起的,我该如何解决?

最佳答案

主要问题是您的 servlet 类没有包。声明一个。

package com.example;

public class HelloServlet extends HttpServlet {

并且在 web.xml 中注册时,请确保包含该包:

<servlet-class>com.example.HelloServlet</servlet-class>

另外,您的类文件应该在 /WEB-INF/classes 目录中,而不是 /WEB-INF/class

webapps/hello/WEB-INF/classes/com/example/HelloServlet.class

关于servlets - java.lang.ClassNotFoundException : HelloServlet at org. apache.catalina.loader.WebappClassLoader.loadClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10380782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com