[英]Jasper Reports Change absolute path to relative path?
我是jasper的新手,我想在jrxml中编译报告并从绝对路径导出到pdf in到相对路径。 目前,代码仅在绝对路径中起作用。
导出到pdf =下载/Reports/ConsumptionReport.jrxml中的Web浏览器jrxml文件夹(在网页内)谢谢:D
public void showReport(int productionNumber) throws JRException {
try {
DBConnectionFactory myFactory = DBConnectionFactory.getInstance();
Connection conn = myFactory.getConnection();
Map map = new HashMap();
map.put("prodNum", productionNumber);
JasperReport jr = JasperCompileManager.compileReport("/Users/user/NetBeansProjects/EGMI/web/Reports/ConsumptionReport.jrxml");
//Fill the report with parameter, connection and the stream reader
JasperPrint jp = JasperFillManager.fillReport(jr, map, conn);
JasperExportManager.exportReportToPdfFile(jp, "/Users/user/NetBeansProjects/EGMI/web/Reports/ConsumptionReport.pdf");
JasperViewer.viewReport(jp, true);
} catch (Exception e) {
e.printStackTrace();
}
}
文件夹层次
EGMI
---Web Pages
----Reports
-----ConsumptionReport.jrxml
解决方案 - servlet
String relativeWebPath = "/Reports";
String absoluteDiskPath = getServletContext().getRealPath(relativeWebPath);
File f = new File(absoluteDiskPath, "ConsumptionReport.jrxml");
使用java.io.File从相对路径获取绝对路径。 ES。
File f = new File("yourRelativePath/ConsumptionReport.jrxml");
JasperReport jr = JasperCompileManager.compileReport(f.getAbsolutePath());
查看问题以查找已部署的Web应用程序的相对路径,我建议您查看这些问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.