public static void generateReportInPdf(Map parameters ) throws JRException, SQLException, ClassNotFoundException
{
Connection conn = Connect.connectMySqlDB();
String jasperPath = ServletActionContext.getServletContext().getRealPath("/voucher/voucher.jasper");
String jrprintPath = ServletActionContext.getServletContext().getRealPath("/voucher/voucher.jrprint");
JasperFillManager.fillReportToFile(jasperPath, parameters, conn);
JasperExportManager.exportReportToPdfFile(jrprintPath);
}
如何在每次保存时使文件名不同?
答案 0 :(得分:3)
您需要将文件名作为参数传递,并使用它来编写pdf
JasperExportManager.exportReportToPdfFile(sourceFileName, destinationFileName)
如果您在Web应用程序中使用jasper-reports,并且需要将响应发送到浏览器,则可以将报告写入OutputStream,然后在响应标头中设置文件名。
byte[] byteArray = JasperExportManager.exportReportToPdf(jasperPrintObject);
httpServletResponse.setHeader("Content-disposition","attachment; filename="+fileName);
httpServletResponse.getOutputStream().write(byteArray);