1
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);

}

如何在每次保存时放置不同的文件名?

4

1 回答 1

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);
于 2012-09-05T10:00:39.653 回答