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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6953956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 18:00:32  来源:igfitidea点击:

javax.servlet.ServletException: Wrapper cannot find servlet class

javaservlets

提问by parsifal

I have made a servlet from "Jasper Reports for Java Develper" (chapter 3) which will show Jasper Report on browser.

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

The servlet look like below:

servlet 如下所示:

public class FirstReportSendToBrowserServlet extends HttpServlet {

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

Then I compiled the servlet and put it into Tomcat. When I fire up tomcat, it works well. But the servlet doesn't work, I get the following exception:

然后我编译了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) 

But the servlet class has already been deployed in Tomcat, can somebody give hints?

但是servlet类已经部署在Tomcat中了,谁能给点提示?

采纳答案by BalusC

As the exception message hints, your servlet class is not in a package (normally the full qualified classname is shown there). You should always put the servlet class (and all other Java classes) in a package.

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

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

public class FirstReportSendToBrowserServlet extends HttpServlet {

    // ...

}

Classes in the default package are invisible to classes which reside in a package (such as Tomcat itself).

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