在已经做好ireport的模板的前提下:
1. 首先获得zk中的session
static HttpSession session = (HttpSession) Sessions.getCurrent()
.getNativeSession();
2.定义Media
private Media media;
3.加载Jasper,设置参数
Map map = new HashMap();
JasperReport jr;
JasperPrint jp = null;
JRAbstractExporter exporter = null;
try {
jr = (JasperReport) JRLoader.loadObject(path + "/factRecord/ireport/factstatute.jasper");//加载Jasper
jp = JasperFillManager.fillReport(jr, map, new JREmptyDataSource());
exporter = new JRRtfExporter();//这里可以选择其他文件格式
ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,
arrayOutputStream);
exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR,Boolean.TRUE);
exporter.exportReport();
arrayOutputStream.close();
media = new AMedia("fact_statute.doc", "rtf", "application/rtf",
arrayOutputStream.toByteArray()); } catch (Exception e) {
e.printStackTrace();
}
return media;
4.用zk组件下载
Filedownload.save(media);