如何将使用 jasper 报告生成的 PDF 文件保存在其中一个项目文件夹中

How to save a PDF file generated with jasper reports in one of the project folders

我有一份 jasper 报告已经可以供用户下载。 但是现在需要将此 PDF 的副本保存到服务器上的特定文件夹中,我有以下代码,但它会产生错误。

            JasperDesign design = JRXmlLoader.load(jrxPath);
            JasperReport report = JasperCompileManager.compileReport(design);                
            JasperPrint print = JasperFillManager.fillReport(report, getParametros());           

            //String pojectPath = "http://localhost:9080/ProjectName/";
            String exportPath = projectPath + "reports/saida/" + "reportName.pdf";
            JasperExportManager.exportReportToPdfFile(print, exportPath);

net.sf.jasperreports.engine.JRRuntimeException: java.io.FileNotFoundException: http:\localhost:9080\RelatoriosDPOC\reports\saida\reportName.pdf
(The syntax for the file name, directory name, or volume label is incorrect.)

我已经试过改路径了。但是我得到了同样的错误。

 String exportPath = projectPath + "reports/saida/";

String exportPath = projectPath + "reports/saida";

我的项目文件夹:

尝试创建一个目录并获取该目录的绝对路径:

  String realPath = getServletContext().getRealPath("/");

  File file = new File(realPath+"/reports/saida/output/");
  file.mkdirs();

  JasperExportManager.exportReportToPdfFile(print, file.getAbsolutePath +"reportName.pdf");