Java程序如何调用.Jasper的文件生成一个PDF文件
答案:1 悬赏:10 手机版
解决时间 2021-01-23 16:40
- 提问者网友:暮烟疏雨之际
- 2021-01-22 20:16
Java程序如何调用.Jasper的文件生成一个PDF文件
最佳答案
- 五星知识达人网友:夜风逐马
- 2021-01-22 21:46
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(保存数据的List对象);
File reportFile = null;
reportFile = new File(this.getServletContext().getRealPath("/report.jasper"));
FileInputStream fis = new FileInputStream(reportFile);
OutputStream os = null;
Map parameters = new HashMap();//报表要用的参数
try {
JasperPrint jasperPrint = JasperFillManager.fillReport(fis, parameters, dataSource);
byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint);
response.setHeader("Content-Disposition", "attachment;filename=temp.pdf");
os = response.getOutputStream();
os.write(bytes);
os.flush();
} catch (JRException e) {
e.printStackTrace();
}finally {
try {
if(os!=null)
os.close();
if(fis!=null)
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}追问
27行报错...请问需要引用什么类包啊...
File reportFile = null;
reportFile = new File(this.getServletContext().getRealPath("/report.jasper"));
FileInputStream fis = new FileInputStream(reportFile);
OutputStream os = null;
Map
try {
JasperPrint jasperPrint = JasperFillManager.fillReport(fis, parameters, dataSource);
byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint);
response.setHeader("Content-Disposition", "attachment;filename=temp.pdf");
os = response.getOutputStream();
os.write(bytes);
os.flush();
} catch (JRException e) {
e.printStackTrace();
}finally {
try {
if(os!=null)
os.close();
if(fis!=null)
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}追问
27行报错...请问需要引用什么类包啊...
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯