java net.sf.jasperreports.engine.JRRuntimeException:java.io.IOException:系统找不到指定的路径

时间:2018-06-07 02:27:40

标签: java jasper-reports ioexception

当我尝试生成大于7MB的大文件(Excel)时,会发生以下异常。低于该大小的文件工作正常。

当我尝试将tomcat升级到v8.5.28时,会发生这种情况。它在tomcat 8.0.14中工作正常。

问题
我可能有什么理由得到这个错误?

下面是stackstrace

net.sf.jasperreports.engine.JRRuntimeException: java.io.IOException: The system cannot find the path specified
at net.sf.jasperreports.engine.export.ooxml.BaseHelper.write(BaseHelper.java:64)
at net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter$1.writeText(JRXlsxExporter.java:1560)
at net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter$1.handle(JRXlsxExporter.java:1553)
at net.sf.jasperreports.engine.export.data.StringTextValue.handle(StringTextValue.java:43)
at net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter.exportText(JRXlsxExporter.java:1572)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportPage(JRXlsAbstractExporter.java:1344)
at net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter.exportPage(JRXlsxExporter.java:271)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReportToStream(JRXlsAbstractExporter.java:1116)
at net.sf.jasperreports.engine.export.JRXlsAbstractExporter.exportReport(JRXlsAbstractExporter.java:964)
at com.test.report.base.jasper.JasperReports.JasperReportXlsPreview(JasperReports.java:230)
at com.test.report.base.jasper.ReportGenerator.doReport(ReportGenerator.java:32)
at com.test.report.web.ui.bean.ReportControl.print(ReportControl.java:869)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

CODE
生成Excel文件

    public String JasperReportXlsPreview(ExternalContext ext, HttpServletResponse response,
            Map<String, Object> mapParameter, JasperQueryResultDataSource queryResult, String reportLocation,
            String reportFilename) {
        String message = "";

        JasperReport jasperReport = null;
        JasperPrint jasperPrint = null;
        JRXlsxExporter exporter = null;
        OutputStream output = null;
        SimpleXlsxReportConfiguration configuration = null;

        reportFilename = reportFilename + ".xlsx";

        try {           
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-disposition", "attachment; filename=\"" + reportFilename + "\"");
            response.setContentLength(response.getBufferSize());
            jasperReport = JasperCompileManager.compileReport(reportLocation);
            jasperPrint = JasperFillManager.fillReport(jasperReport, mapParameter, queryResult);
            exporter = new JRXlsxExporter();
            exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
            exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(output));
            configuration = new SimpleXlsxReportConfiguration();
            configuration.setOnePagePerSheet(false);
            configuration.setWhitePageBackground(true);
            configuration.setDetectCellType(true);
            exporter.setConfiguration(configuration);
            exporter.exportReport();            
        } catch (Exception e) {
            e.printStackTrace();
            return "Error: " + e.getMessage();
        } finally {
            queryResult.destroy();
            jasperReport = null;
            jasperPrint = null;
            exporter = null;
            configuration = null;
            response = null;
            ext = null;
            reportFilename = null;
            queryResult = null;
            reportLocation = null;
            mapParameter = null;
        }

        System.gc();

        return message;
}

依赖
jasperreport:6.5 Java:8

1 个答案:

答案 0 :(得分:0)

错误是由Tomcat使用不存在/无效的临时目录引起的。

验证Tomcat脚本为java.io.tmpdir Java系统属性设置的值。