日期:2014-05-17 浏览次数:21254 次
<queryString language="hql"> <![CDATA[from Aircraft aircraft where country = $P{countryCode} order by aircraft.id]]> </queryString>
//输出流 ServletOutputStream servletOutputStream = response.getOutputStream(); //输入流 InputStream reportStream = getServlet().getServletConfig() .getServletContext().getResourceAsStream("xxxx/xxxx.jasper"); //设格式为PDF文件 response.setContentType("application/pdf"); //Session的创建不变 SessionFactory sessionFactory = new Configuration().configure(). buildSessionFactory(); Session session = sessionFactory.openSession(); //要在Map里面放入Session Map parameterMap = new HashMap(); parameterMap.put(JRHibernateQueryExecuterFactory.PARAMETER_ HIBERNATE_SESSION, session); //使用JasperFileManager的这个方法,生成jprint文件,如果在WEB里面,可以不生成 //JasperFillManager.fillReportToFile("/xxx/xxxx.jasper","/xxx/xxx.jprint",session); //输出PDF流到WEB页 JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, parameterMap); session.close(); servletOutputStream.flush(); servletOutputStream.close(); return mapping.getInputForward();