JRBeanCollectionDataSourcedataSource=newJRBeanCollectionDataSource(保存数据的List对象);FilereportFile=null;reportFile=newFile(this.getServletContext().getRealPath("/repor...
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();
}
}
能够打印,但是在机器纸上打印很大,一张纸不够打印
展开