我正在学习Servlets概念。最初,ITutorial引用了此链接并研究HelloWorld示例。
在提交带有名称和年龄的JSP表单时,出现以下错误。请就必须做什么提供建议。
我放置的文件的位置如下,
C:\ Program Files \ Apache Software Foundation \ Tomcat 5.5 \ webapps \ servletexmple \ hello.jsp
C:\ Program Files \ Apache Software Foundation \ Tomcat5.5 \ webapps \ servletexmple \ example \ HelloServlet.class
C:\ Program Files \ Apache Software Foundation \ Tomcat 5.5 \ webapps \ servletexmple \ WEB-INF \ web.xml
Exception: javax.servlet.ServletException: Wrapper cannot find servlet class example.HelloServlet or a class it depends on org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870) org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685) java.lang.Thread.run(Unknown Source) Root Cause: java.lang.ClassNotFoundException: example.HelloServlet org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1205) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870) org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685) java.lang.Thread.run(Unknown Source)
我的web.xml文件包含以下内容,
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <servlet> <servlet-name>HelloServlet</servlet-name> <servlet-class>example.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloServlet</servlet-name> <url-pattern>/servletexmple</url-pattern> </servlet-mapping> </web-app>
您必须将类文件放入中webapps/servletexmple/WEB-INF/classes。在那里,您应该遵循包的结构。即将文件放在
webapps/servletexmple/WEB-INF/classes
webapp / servletexample / WEB-INF / classes / example / HelloServlet
在web.xml中,您应该使用servlet的完全限定名称。即example.HelloServlet。
example.HelloServlet