struts2 X ireport实现PDF下载
1、js端方法调用
<a href="../xx/pdfDownload!exportToPdfReport.action?oid=123" target="_blank"><span>导出PDF</span></a>
2、后端方法
public void exportToPdfReport() throws IOException { Map<String, Object> map = Maps.newHashMap(); // pdf报表查询条件 map.put("ids", oid); // 获取pdf模板文件路径 String pdfTemplateRealPath = CommonUtil.getPdfxxxx(); exportToPdf(pdfTemplateRealPath , map, getResponse().getOutputStream()); } public void exportToPdf(String reportName, Map<String, Object> paramMap, OutputStream outputStream) { InputStream inputStream = null; HttpServletResponse resp = super.getResponse(); resp.setCharacterEncoding("utf-8"); resp.setContentType("application/pdf"); resp.setHeader("content-disposition", "attachment;filename=\"xxx.pdf\""); try { inputSteam = new FileInputStream(reportName); } catch () { } Connection connection = null; try { connection = dataSource.getConnection(); } catch () { } try { JasperRunManager.runReportToPdfStream(inputStream, outputStream, paramMap, connection); outputStream.flush(); outputStream.close(); } catch () { } catch () { } }
3、需要引入的jar包

4、调试过程中遇到的问题解决
https://blog.csdn.net/ocean20/article/details/6314144
5、pdf报表模板

PS: .jasper文件是编译后的,是在项目中起作用的

浙公网安备 33010602011771号