gpt4 book ai didi

java - Tomcat Servlet 类NotFoundException

转载 作者:行者123 更新时间:2023-11-30 05:57:29 25 4
gpt4 key购买 nike

我创建了简单的 servlet。

package servlets;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class testServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.print("TEST");
out.close();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}
}

web.xml配置

<servlet>
<servlet-name>testServlet</servlet-name>
<servlet-class>servlets.testServlet</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>testServlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>

启动日志

cmd /c ""D:\Program Files\Java\jdk1.6.0_24\bin\java" -Dcatalina.base=C:\Users\Administrator\.IntelliJIdea10\system\tomcat\_WebApplication "-Dcatalina.home=D:\Program Files\Apache Software Foundation\Tomcat 7.0" "-Djava.io.tmpdir=D:\Program Files\Apache Software Foundation\Tomcat 7.0\temp" -cp "D:\Program Files\Apache Software Foundation\Tomcat 7.0\bin\bootstrap.jar;D:\Program Files\Apache Software Foundation\Tomcat 7.0\bin\tomcat-juli.jar" org.apache.catalina.startup.Bootstrap start"
13 квіт 2011 23:35:47 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Program Files\Java\jdk1.6.0_24\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:\Program Files\JetBrains\IntelliJ IDEA 10.0.2\bin\..\.\bin;C:\Program Files\Haskell\bin;D:\Program Files\Haskell Platform\2011.2.0.0\lib\extralibs\bin;D:\Program Files\Haskell Platform\2011.2.0.0\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\bin\;C:\Program Files\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;D:\Program Files\TortoiseSVN\bin;D:\Program Files\Microsoft Network Monitor 3\;D:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Users\Administrator\AppData\Roaming\cabal\bin;d:\program files\jetbrains\intellij idea 10.0.2\jre\jre\bin
13 квіт 2011 23:35:48 org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
13 квіт 2011 23:35:48 org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
13 квіт 2011 23:35:48 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 565 ms
13 квіт 2011 23:35:48 org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
13 квіт 2011 23:35:48 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.12
13 квіт 2011 23:35:48 org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor ROOT.xml from C:\Users\Administrator\.IntelliJIdea10\system\tomcat\_WebApplication\conf\Catalina\localhost
13 квіт 2011 23:35:48 org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet testServlet as unavailable
13 квіт 2011 23:35:48 org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet threw load() exception
java.lang.**ClassNotFoundException: servlets.testServlet**
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1062)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1010)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4935)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5262)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5257)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

为什么会出现错误?

最佳答案

您必须拥有此文件:

webapps/WEB-INF/classes/servlets/testServlet.class

也就是说,请使用 pascal 大小写而不是驼峰大小写命名您的类 - TestServlet

关于java - Tomcat Servlet 类NotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5655417/

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