我正在创建api以PDF格式下载我的报告。 为此,我使用java(火花框架)和碧玉报告工具 一切工作正常。无法使用Jasper报告设置默认文件名
问题是,当我从邮递员打我的API为PDF的默认名称为“response.pdf.pdf”,我希望它是“report.pdf”
这里是我的方法。
private Route getReport = (req,res)->{
try{
res.raw().setHeader("Content-Disposition", "attachment; filename= \"report.pdf\"");
res.raw().setContentType("application/pdf");
JRDataSource dataSource = new JREmptyDataSource();
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("cin", "556293-9982");
dataMap.put("financialYear","2009-05-01 - 2010-04-30");
JasperPrint jasperPrint = JasperFillManager.fillReport("reports/front-page.jasper", dataMap,dataSource);
JasperExportManager.exportReportToPdfStream(jasperPrint,res.raw().getOutputStream());
}catch(Exception ex){
res.type(ApplicationConstants.JSON_APPLICATION_CONTENT_TYPE);
throw new BusinessExceptions(ex, ApiErrorEnumerations.ERR_DOWNLOADING_REPORT);
}finally{
res.raw().flushBuffer();
res.raw().getOutputStream().close();
}
return res.raw();
};
请建议我哪里出错了。
@AlexK我们必须编写关于“exportReportToPdfStream”的报告,并且链接的解决方案使用“exportReportToPdfFile”。 –
重复:[如何更改与JasperReports pdf文件生成的名称?](http://stackoverflow.com/q/41218899/876298) –
@亚历克斯仍然没有运气。 –