当前位置: 代码迷 >> ASP >> jasper report 第一个事例
  详细解决方案

jasper report 第一个事例

热度:746   发布时间:2013-01-26 13:47:01.0
jasper report 第一个例子
 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) {
							}
						}
					}
			} 

?

  相关解决方案