javax.servlet.ServletException:Wrapper找不到servlet类

时间:2011-08-05 09:11:07

标签: java servlets

我从“Jasper Reports for Java Develper”(第3章)制作了一个servlet,它将在浏览器上显示Jasper Report。

servlet如下所示:

public class FirstReportSendToBrowserServlet extends HttpServlet {

    //just implement doGet in the block
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {               
        // ...            
    }
}

然后我编译了servlet并将其放入Tomcat。当我启动tomcat时,它运行良好。但是servlet不起作用,我得到以下异常:

javax.servlet.ServletException: Wrapper cannot find servlet class FirstReportSendToBrowserServlet or a class it depends on
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    java.lang.Thread.run(Thread.java:619) 

但是servlet类已经部署在Tomcat中,有人可以给出提示吗?

1 个答案:

答案 0 :(得分:1)

正如异常消息提示,您的servlet类不在包中(通常在那里显示完整的限定类名)。您应该始终将servlet类(以及所有其他Java类)放在一个包中。

package com.parsifal; // <--- Here.

public class FirstReportSendToBrowserServlet extends HttpServlet {

    // ...

}

默认包中的类对于驻留在包中的类(例如Tomcat本身)是不可见的。