我在jsf中使用JasperReports 4.5。目前,我正在使用Netbeans 4。
在执行此行exporterXLS.exportReport()
时,我遇到了以下运行时异常:
net.sf.jasperreports.engine.JRException: Error trying to export to file : TS150804.xls
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReport(JRXlsAbstractExporter.java:501)
at nic.scrollupload.bean.PaymentStatusReport.printXlReport(PaymentStatusReport.java:307)
at nic.scrollupload.bean.PaymentStatusReport.generateReport(PaymentStatusReport.java:409)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at filters.AuthFilter.doFilter(AuthFilter.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
我的代码:
public boolean printXlReport(List<PaymentStatusReportDobj> successList, HashMap parameters, String filename)throws JRException {
FacesContext facescontext1 = FacesContext.getCurrentInstance();
boolean result = false;
// JRResultSetDataSource dataSource = new JRResultSetDataSource(rs);
// ======================
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(successList);
// ==========================
JasperReport jasperReport;
JasperPrint jasperPrint;
try {
ServletContext sc = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
String urlpath = sc.getRealPath(File.separator);
String filePath = urlpath + "reports" + File.separator + "PaymentStatusReport.jrxml";
JasperDesign jasperDesign = JRXmlLoader.load(filePath);
jasperReport = JasperCompileManager.compileReport(jasperDesign);
HttpServletResponse response = (HttpServletResponse) facescontext1.getExternalContext().getResponse();
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource);
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, jasperPrint);
exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS, Boolean.TRUE);
exporterXLS.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, filename + ".xls");
exporterXLS.exportReport();
File f = new File(filename + ".xls");
FileInputStream fin = new FileInputStream(f);
ServletOutputStream servletOutputStream = response.getOutputStream();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;zoom=1000=OpenActions;filename=" + filename + ".xls");
byte[] buffer = new byte[1024];
int n = 0;
while ((n = fin.read(buffer)) != -1) {
servletOutputStream.write(buffer, 0, n);
}
servletOutputStream.flush();
fin.close();
servletOutputStream.close();
facescontext1.responseComplete();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
请有人解决此运行时异常。