我收到错误消息:Error While Displaying Report Page : See Console for Details

我有以下所有罐子


iText-2.1.7.js2
杰克逊核心2.1.4
jasperreports-5.6.0
jasperreports-chart-themes-5.6.0
jasperreports-core-renderer
jasperreports-fonts-5.6.0
jcommon-1.0.15
jfreechart-1.0.13


有人可以告诉我我错了吗?

堆栈跟踪:

      java.lang.ClassCastException:       net.sf.jasperreports.engine.export.DefaultExporterFilterFactory cannot be cast       to net.sf.jasperreports.engine.export.ExporterFilterFactory
     at          net.sf.jasperreports.engine.export.ExporterFilterFactoryUtil.getFilterFactory(Ex     porterFilterFactoryUtil.java:53)
    at     net.sf.jasperreports.engine.JRAbstractExporter.createFilter(JRAbstractExporter.j     ava:1136)
    at net.sf.jasperreports.engine.JRAbstractExporter.initReport(JRAbstractExporter.jav     a:726)
      at   net.sf.jasperreports.engine.export.JRGraphics2DExporter.initReport(JRGraphics2DE     xporter.java:255)
    at      net.sf.jasperreports.engine.JRAbstractExporter.setCurrentExporterInputItem(JRAbs     tractExporter.java:567)
     at net.sf.jasperreports.engine.export.JRGraphics2DExporter.exportReportToGraphics2D     (JRGraphics2DExporter.java:285)
     at net.sf.jasperreports.engine.export.JRGraphics2DExporter.exportReport(JRGraphics2     DExporter.java:236)
    at net.sf.jasperreports.view.JRViewer.paintPage(JRViewer.java:2121)
    at      net.sf.jasperreports.view.JRViewer$PageRenderer.paintComponent(JRViewer.java:227     1)
     at javax.swing.JComponent.paint(JComponent.java:1054)
    at javax.swing.JComponent.paintChildren(JComponent.java:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JComponent.paintChildren(JComponent.java:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JComponent.paintChildren(JComponent.java:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JComponent.paintChildren(JComponent.java:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JViewport.paint(JViewport.java:731)
    at javax.swing.JComponent.paintChildren(JComponent.java:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JComponent.paintChildren(JComponent.java:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JComponent.paintChildren(JComponent.java:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JComponent.paintChildren(JComponent.java:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JComponent.paintChildren(JComponent.java:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
     at javax.swing.JComponent.paintChildren(JComponent.java:887)
    at javax.swing.JComponent.paint(JComponent.java:1063)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:585)
    at javax.swing.JComponent.paintChildren(JComponent.java:887)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5226)
    at      javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:     1529)
    at      javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1452)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1249)
    at javax.swing.JComponent.paint(JComponent.java:1040)
    at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:39)
    at      sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:78)
    at      sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:115)
    at java.awt.Container.paint(Container.java:1967)
    at java.awt.Window.paint(Window.java:3877)
    at javax.swing.RepaintManager$3.run(RepaintManager.java:819)
    at javax.swing.RepaintManager$3.run(RepaintManager.java:796)
     at java.security.AccessController.doPrivileged(Native Method)
    at      java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:7     6)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:796)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:769)
    at      javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:718)
    at javax.swing.RepaintManager.access$1100(RepaintManager.java:62)
    at      javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1677)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at      java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:7     6)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242      )
    at      java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150     )
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)


我的Bean代码:

 public class PortoflioListJasper {
    public PortoflioListJasper() {
      }

      public String runReportAction() {
          System.out.println("On ReportAction");
          DCIteratorBinding empIter = (DCIteratorBinding)       getBindings().get("*Iterator Name*");
            System.out.println("On Iterator");
          Integer var = (Integer)      (empIter.getCurrentRow().getAttribute("Id"));
            System.out.println("On Attribute");
          Map m = new HashMap();
            System.out.println("On Map EmpID");
          m.put("name",var );// where employeeId is a jasper report       parameter
          System.out.println("On Map " +portfolioId);
          try
          {
            runReport("Reporta.jasper", m);
          }
          catch (Exception e)
          {
          }
          return null;
          }
                public BindingContainer getBindings()
                       {
                       return       BindingContext.getCurrent().getCurrentBindingsEntry();
                       }

                       public Connection getDataSourceConnection(String       dataSourceName)
                         throws Exception
                       {
                         Context ctx = new InitialContext();
                         DataSource ds =       (DataSource)ctx.lookup(dataSourceName);
                   return ds.getConnection();
                 }

                 private Connection getConnection()
                 {
                   try
                   {
                   System.out.println("On Connection");
                 return getDataSourceConnection("*DataSource Name*");//       datasource name should be defined in weblogic

                         }
                   catch (Exception e) {
                       System.out.println("On Catch");
                       e.printStackTrace();
                       return null;
                   }
                 }


                 public  ServletContext getContext()
                 {
                         return           (ServletContext)getFacesContext().getExternalContext().getContext();
                       }
                 public  HttpServletResponse getResponse()
                 {
                   return       (HttpServletResponse)getFacesContext().getExternalContext().getResponse();
                       }
                       public static FacesContext getFacesContext()
                       {
                         return FacesContext.getCurrentInstance();
                 }
                 public void runReport(String repPath, java.util.Map param) throws Exception
                 {
                 Connection conn = null;
                 try
                 {
                   HttpServletResponse response = getResponse();
                     System.out.println("Response : " +response);
                   ServletOutputStream out = response.getOutputStream();
                   response.setHeader("Cache-Control", "max-age=0");
                   response.setContentType("application/octet-stream");
                   ServletContext context = getContext();
                         InputStream fs = context.getResourceAsStream("/Reports/"             + repPath);
                           System.out.println("Response : " +repPath);
                           System.out.println("Response : " +fs);

                   JasperReport template = (JasperReport)     JRLoader.loadObject(fs);
                           System.out.println("Template : " +template);
                      template.setWhenNoDataType(WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL);
                   conn = getConnection();

                         JasperPrint print =       JasperFillManager.fillReport(template, param, conn);
                           System.out.println("PDF" +print);
                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
                         JasperExportManager.exportReportToPdfStream(print, baos);


                     System.out.println("PDF" +baos);
                     out.write(baos.toByteArray());
                    JasperViewer view = new JasperViewer(print,false);
                    view.setVisible(true);
                     System.out.println("Printed");
                     out.flush();
                     out.close();
                     FacesContext.getCurrentInstance().responseComplete();

                  }
                 catch (Exception jex)
                 {
                   jex.printStackTrace();
                 }
                 finally
                 {
                   close(conn);
                 }
                 }

                 public void close(Connection con)
                 {
                  if (con != null)
                  {
                    try
                    {
                      con.close();
                    }
                    catch (Exception e)
                    {
                    }
                  }
                 }
      }


我希望报表显示在屏幕上。

我想念任何罐子吗?

最佳答案

我们在adf中渲染了很多pdf。这是一个这样的例子。随附所需罐子清单供参考。
我的Jasper报告(MainReport.jasper)捆绑在一个jar文件中,并放在应用程序中。

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    try {
        response.setContentType("application/pdf");
        Gson gson = new Gson();
        System.out.println("Request in GeneratePDFServlet ::" + request.getParameter("obj"));
        PDFReportQuoteDeatails pdfReportQuoteDeatails = gson.fromJson(request.getParameter("obj"), PDFReportQuoteDeatails.class);
        System.out.println(pdfReportQuoteDeatails);
        InputStream is = (InputStream)getPdfReportAsInputStream(pdfReportQuoteDeatails);
        OutputStream os = response.getOutputStream();
        // is = (InputStream)getPdfReportAsInputStream(pdfReportQuoteDeatails);
        int idx;
        byte[] buffer = new byte[10240];
        while ((idx = is.read(buffer, 0, 10240)) != -1) {
            os.write(buffer, 0, idx);
        }
        System.out.println("Finished Writing..");
        os.close();
        response.flushBuffer();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}


public InputStream getPdfReportAsInputStream(PDFReportQuoteDeatails quoteDetails) {
    try {
        Long maxPeriod = 0L;
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("MainReport.jasper");
        if (is == null)
            System.out.println("******FILE is null*******");
        else
            System.out.println("FILE is not null");
        JasperPrint printFileName;
        // JasperDesign jd = JRXmlLoader.load(is);
        //   JasperReport compiledReport = JasperCompileManager.compileReport(jd);
        SortedMap<Long, SortedSet<Long>> periodMap = new TreeMap<Long, SortedSet<Long>>();
        for (PDFQuoteLineBean qlb : quoteDetails.getQuoteLines()) {
            SortedSet<Long> milagesForPeriod = periodMap.get(qlb.getPeriod());
            if (milagesForPeriod == null) {
                milagesForPeriod = new TreeSet<Long>();
                System.out.println("qlb.getPeriod():" + qlb.getPeriod());
                System.out.println("milagesForPeriod:" + milagesForPeriod);
                periodMap.put(qlb.getPeriod(), milagesForPeriod);
                if (maxPeriod < qlb.getPeriod()) {
                    maxPeriod = qlb.getPeriod();
                }
            }
            milagesForPeriod.add(qlb.getMileage());
        }
        List<String> quoteHeaders = new ArrayList<String>();
        for (Map.Entry<Long, SortedSet<Long>> e : periodMap.entrySet()) {
            for (Long mileage : e.getValue()) {
                quoteHeaders.add(getHeader(e.getKey(), mileage));
            }
        }
        List list = getQuoteDetailsBeanList(quoteDetails.getQuoteLines(), quoteHeaders);
        JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(list,false);
        Map parameters = new HashMap();
        parameters.put("custAddrLine1", quoteDetails.getCustAddrLine1());
        parameters.put("custAddrLine2", quoteDetails.getCustAddrLine2());
        parameters.put("custAddrPoBox", quoteDetails.getCustAddrPoBox());
        parameters.put("custAddrState", quoteDetails.getCustAddrState());
        parameters.put("CustAddrCountry", quoteDetails.getCustAddrCountry());
        parameters.put("custPhoneNo", quoteDetails.getCustPhoneNo());
        parameters.put("custFaxNo", quoteDetails.getCustFaxNo());
        parameters.put("quoteNo", quoteDetails.getQuoteNumber());
        parameters.put("quoteSubject", quoteDetails.getOpportunityProduct() + " Rates");
        parameters.put("quoteMsg",
                       "We thank you for your enquiry. As desired, please find below our " + quoteDetails.getOpportunityProduct().toLowerCase() + " rates for the vehicle(s) as mentioned below");
        parameters.put("custName", quoteDetails.getCustomerName());
        parameters.put("contactName", quoteDetails.getContactPointName());
        parameters.put("quoteHeader1", quoteHeaders.size() > 0 ? quoteHeaders.get(0) : null);
        parameters.put("quoteHeader2", quoteHeaders.size() > 1 ? quoteHeaders.get(1) : null);
        parameters.put("quoteHeader3", quoteHeaders.size() > 2 ? quoteHeaders.get(2) : null);
        parameters.put("quoteHeader4", quoteHeaders.size() > 3 ? quoteHeaders.get(3) : null);
        parameters.put("quoteDate", quoteDetails.getQuoteDate());
        parameters.put("salesManName", quoteDetails.getSalesManName());
        parameters.put("salesManEmail", quoteDetails.getSalesManEmail());
        parameters.put("salesManContactNo", quoteDetails.getSalesManConatactNo());
        parameters.put("insuranceExcess", quoteDetails.getInsuranceExcess() != null && quoteDetails.getInsuranceExcess().trim().length() > 0 ? quoteDetails.getInsuranceExcess() : "0");
        parameters.put("trafficViolationCharges",
                       quoteDetails.getTrafficViolationCharges() != null && quoteDetails.getTrafficViolationCharges().trim().length() > 0 ? quoteDetails.getTrafficViolationCharges() :
                       "0");
        parameters.put("salikServiceCharge",
                       quoteDetails.getSalikServiceCharge() != null && quoteDetails.getSalikServiceCharge().trim().length() > 0 ? quoteDetails.getSalikServiceCharge() : "0");
        String terminationClause = "";
        if (maxPeriod != null) {
            if (maxPeriod / 12 == 1) {
                terminationClause = "The contract is non Cancellable in the first year. ";
            } else if (maxPeriod / 12 == 2) {
                terminationClause = "The contract is Non cancellable in the first year.\n" +
                        "If the contract is cancelled in the second year , then 3 months rentals would be charged as penalty.\n ";
            } else if (maxPeriod / 12 == 3) {
                terminationClause = "The contract is Non cancellable in the first year.\n" +
                        "If the contract is cancelled in the second year , then 4 months rentals would be charged as penalty.\n" +
                        "If the contract is cancelled in the third  year , then 3 months rentals would be charged as penalty.\n";
            } else {
                terminationClause = "The contract is Non cancellable in the first year.\n" +
                        "If the contract is cancelled in the second year , then 5 months rentals would be charged as penalty.\n" +
                        "If the contract is cancelled in the third  year , then 4 months rentals would be charged as penalty.\n" +
                        "If the contract is cancelled in the fourth year , then 3 months rentals would be charged as penalty.\n";
            }
        }
        parameters.put("terminationClause", terminationClause);
        if (list != null && list.size() > 0) {
            System.out.println(quoteDetails.getQuoteLines().size() + " Quote lines detected");
            parameters.put("noOfLines", list.size());
            printFileName = JasperFillManager.fillReport(is, parameters, beanColDataSource);
        } else {
            System.out.println("No Quote lines detected");
            parameters.put("noOfLines", 1);
            printFileName = JasperFillManager.fillReport(is, parameters, new JREmptyDataSource());
        }
        if (printFileName != null) {
            is = new ByteArrayInputStream(JasperExportManager.exportReportToPdf(printFileName));
            return is;
        } else {
            System.out.println("getPdfReportAsInputStream::after fillReport ::: printFileName is null");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

10-07 22:42