jasper打印文件出现空白页面


EG:打印文件结果打印出一片空白  

原因:使用了null的数据源而不是JREmptyDataSource

 

以下为正确代码

public <T> List<JasperPrint> createJasperPrint_1(List<T> list,
Map<String, Object> imgMap, Map<String, Object> pathMap) {
List<JasperPrint> printList = new ArrayList<JasperPrint>();
if (pathMap != null) {
try {
for (String kn : pathMap.keySet()) {
ServletContext context = ServletActionContext
.getRequest().getSession().getServletContext();
String file = context.getRealPath(String.valueOf(pathMap.get(kn)));
JasperReport report = (JasperReport) JRLoader
.loadObject(file);
JRDataSource source = new JRBeanCollectionDataSource(
list);

JasperPrint print = new JasperPrint();
//如果数据集为空 则应该使用JREmptyDataSource 否则会打印空白页面
if (list == null) {
print = JasperFillManager.fillReport(
report, imgMap, new net.sf.jasperreports.engine.JREmptyDataSource());
} else {
print = JasperFillManager.fillReport(
report, imgMap, source);
}
if (print != null)
printList.add(print);
}

} catch (JRException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
return printList;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM