发布网友 发布时间:2022-04-23 22:46
共1个回答
热心网友 时间:2023-10-12 15:51
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<String,Object> parameters = new HashMap<String,Object>();//报表要用的参数
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行报错...请问需要引用什么类包啊...