Jasper Reports动态报告——HTTPServlets中的DRException

Jasper Reports Dynamic Reports - DRException in HTTPServlets

我有一个调用 Jasper 报告的 servlet class。

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
        ReportGeneratorModel.generateReport();
        response.sendRedirect("report.jsp");
}

ReportGeneratorModel 调用 MYSQL 数据库,然后生成报告。

public static void generateReport() {
    Connection connection = null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/cleanhandsreport?"+"user=Manager&password=PASSWORD");
    } catch (SQLException e) {
        e.printStackTrace();
        return;
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return;
    }

    JasperReportBuilder report = DynamicReports.report();//a new report
    report
      .columns(
          Columns.column("HospitalID", "HospitalID", DataTypes.stringType()),
          Columns.column("GroupID", "GroupID", DataTypes.stringType()), 
          Columns.column("HandWashViolation", "HandWashViolation", DataTypes.stringType()))
      .title(//title of the report
          Components.text("CleanHands Report")
          .setHorizontalAlignment(HorizontalAlignment.CENTER))
          .pageFooter(Components.pageXofY())//show page number on the page footer
          .setDataSource("SELECT HospitalID, GroupID, Time, HandWashViolation FROM report", 
                                  connection);

    try {
                //show the report
        report.show();

                //export the report to a pdf file
        report.toPdf(new FileOutputStream("report.pdf"));
    } catch (DRException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
  }

我收到以下错误消息

    Jan 31, 2015 2:56:44 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [rbccps.cleanhands.report.controller.ReportHomeServletController] in context with path [/CleanHandsReport] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: net.sf.dynamicreports.report.exception.DRException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at rbccps.cleanhands.report.controller.ReportHomeServletController.doPost(ReportHomeServletController.java:36)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

我的类路径中有 dynamicreports-4.0.0/lib 文件夹中的所有 jar 文件以及 dynamicreports-core-4.0.0.jar。

当我尝试将报告作为独立的 Java 应用程序时,一切正常。

我尝试在 generateReport() 方法中添加一些日志。 None 其中的一些正在打印,即使它们位于方法的顶部。

非常感谢有关此问题的任何指示。

我得到了 Web 应用程序 运行。问题在于 jar 文件放置。对于网络应用程序,所有罐子都应放在 WEB-INF/lib 目录中 Tomcat 到 read/recognize 罐子。

我恳请管理员关闭问题。干杯。