1
下面這是我的代碼: -使用JasperPrintManager.printReport打印jasper報告時出錯(print,true);
Map parameters = new HashMap();
parameters.put("printer", "1010111");
FileInputStream file = new FileInputStream(new File(getServletContext().getRealPath("/Reports/report1.jasper")));
JasperPrint print = JasperFillManager.fillReport(file, parameters, new JRBeanCollectionDataSource(reports));
JasperPrintManager.printReport(print, true);
我要打印的頁面碧玉。在使用「JasperPrintManager.printReport(print,false)」時沒有任何問題,但是當我使用「true」時,出現以下錯誤。
Severe: net.sf.jasperreports.engine.JRException: Error printing report.
at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:214)
at net.sf.jasperreports.engine.JasperPrintManager.print(JasperPrintManager.java:242)
at net.sf.jasperreports.engine.JasperPrintManager.print(JasperPrintManager.java:129)
at net.sf.jasperreports.engine.JasperPrintManager.printReport(JasperPrintManager.java:326)
at Reports.Closing_Report_Report.doGet(Closing_Report_Report.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.awt.HeadlessException
at sun.awt.windows.WPrinterJob.printDialog(WPrinterJob.java:576)
at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:198)
... 33 more
非常感謝Petter。猜猜我需要將它導出爲pdf。你可以建議我有什麼好的地方來學習這個,我對此很陌生。 –
我的榮幸,http://www.tutorialspoint.com/jasper_reports/jasper_exporting_reports.htm,關於這個問題,有很多關於SO –
的問題,謝謝它的工作...... :)你知道如何打開pdf作爲準備好打印在jsp頁面加載? –