我创建了简单的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
TestServlet