public void jsperReport(){
List purList=new ArrayList();;
User user=new User("zhangsan","上海","男",22);
purList.add(user);
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(purList);
Map<String,Object> pmap = new HashMap<String,Object>();
//map.put来存放parameter,以便在页面中通过$p{}获取
pmap.put("address", "address");
pmap.put("note", "note");
InputStream is = null;
try {
is = this.getClass().getClassLoader().getResourceAsStream("jasper/xxx.jrxml");
JasperDesign jasperDesign = JRXmlLoader.load(is);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, pmap, ds);
if (jasperPrint != null&& !jasperPrint.getPages().isEmpty()) {
// 打印预览
JasperViewer.viewReport(jasperPrint, false);
} else {
return;
}
} catch (JRException e) {
e.printStackTrace();
return;
}
finally
{
if(null != is)
{
try {
is.close();
} catch (IOException e) {
}
}
}
}
?