@Action("report_exportJasperPdf")
public String exportJasperPdf() throws Exception{
//查询出满足当前条件 结果数据
List<WayBill> wayBills = wayBillService.findWayBills(model);
//下载导出
//设置头信息
ServletActionContext.getResponse().setContentType("application/pdf");
String filename = "运单数据.pdf";
String agent = ServletActionContext.getRequest().getHeader("user-agent");
filename = FileUtils.encodeDownloadFilename(filename, agent);
ServletActionContext.getResponse().setHeader("Content-Disposition",
"attachment;filename="+filename);
//根据JasperReport模板生成PDF
//读取模板文件
String jrxml = ServletActionContext.getServletContext().getRealPath(
"/WEB-INF/jasper/waybill.jrxml");
JasperReport report = JasperCompileManager.compileReport(jrxml);
//设置模板数据
//parameter变量
Map<String,Object> parameters = new HashMap<String,Object>();
parameters.put("company", "传智播客");
//Field变量
JasperPrint jasperPrint = JasperFillManager.fillReport(
report, parameters,new JRBeanCollectionDataSource(wayBills));
//生成PDF客户端
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,
ServletActionContext.getResponse().getOutputStream());
exporter.exportReport();//导出
return NONE;
}