java net.sf.jasperreports.engine.JRRuntimeException: java.io.IOException: 系统找不到指定的路径
java net.sf.jasperreports.engine.JRRuntimeException: java.io.IOException: The system cannot find the path specified
当我尝试生成大于 7MB 的大文件 (Excel) 时,出现以下异常。小于该大小的文件工作正常。
当我尝试将 tomcat 升级到 v8.5.28 时发现发生了这种情况。它在 tomcat 8.0.14.
中运行良好
问题
出现此错误的原因可能是什么?
下面是堆栈跟踪
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.writeText(JRXlsxExporter.java:1560)
at net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter.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)
代码
生成 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;
}
依赖关系
碧玉报告:6.5
Java: 8
错误是由 Tomcat 使用 inexisting/invalid 临时目录引起的。
验证 Tomcat 脚本为 java.io.tmpdir
Java 系统设置的值 属性。
当我尝试生成大于 7MB 的大文件 (Excel) 时,出现以下异常。小于该大小的文件工作正常。
当我尝试将 tomcat 升级到 v8.5.28 时发现发生了这种情况。它在 tomcat 8.0.14.
中运行良好问题
出现此错误的原因可能是什么?
下面是堆栈跟踪
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.writeText(JRXlsxExporter.java:1560)
at net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter.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)
代码
生成 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;
}
依赖关系
碧玉报告:6.5
Java: 8
错误是由 Tomcat 使用 inexisting/invalid 临时目录引起的。
验证 Tomcat 脚本为 java.io.tmpdir
Java 系统设置的值 属性。