当前位置: 代码迷 >> Java Web开发 >> 关于Servlet报 Wrapper cannot find servlet class 异常,请教怎么解决
  详细解决方案

关于Servlet报 Wrapper cannot find servlet class 异常,请教怎么解决

热度:393   发布时间:2016-04-17 10:39:28.0
关于Servlet报 Wrapper cannot find servlet class 错误,请问如何解决?
一个简单的servlet程序,报如下错误:

javax.servlet.ServletException: Wrapper cannot find servlet class java.com.servlet.TestServlet or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:212)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
java.lang.Thread.run(Thread.java:619)


root cause 

java.lang.ClassNotFoundException: java.com.servlet.TestServlet
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:212)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
java.lang.Thread.run(Thread.java:619)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.9 logs.


我用的是MyEclipse8.5 + tomcat6.0 实现的

主程序是:TestServlet.java ,位于包java.com.servlet里,程序代码非常简单:如下

package java.com.servlet;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("doGet");

}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doGet(request,response);
}

}

web.xml的配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
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_2_5.xsd">
  <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>java.com.servlet.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/TestServlet</url-pattern>
</servlet-mapping>
</web-app>

然后在浏览器中输入:http://localhost:8080/J2EE/TestServlet

怎么会报上面所述的错误呢?servlet-api.jar也导入了,真的不明白,困扰了好久,请高手指教,谢啦!~~~

------解决方案--------------------
主程序是:TestServlet.java ,位于包java.com.servlet里,程序代码非常简单:如下

注意你的包名,,..居然是java.com 你这样将会导致类加载错误

换下包名的名称就好了,,,程序没什么错误
  相关解决方案