梦幻之旅

DEBUG - 天道酬勤

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  671 随笔 :: 6 文章 :: 256 评论 :: 0 Trackbacks
Class.forName("com.mysql.jdbc.Driver");
  
  Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
   
  File exe_rpt = new File(request.getRealPath("reports/tableprint.jasper"));
  
  Map parameters = new HashMap();
  
  parameters.put("area", sql);
  parameters.put("year", year);
  
  JasperPrint jasperPrint = JasperFillManager.fillReport(exe_rpt.getPath(),parameters,conn);
   
  request.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
    
  
  byte[] bytes = JasperRunManager.runReportToPdf(exe_rpt.getPath(),parameters,conn);
     response.setContentType("applicationf");
     response.setHeader("Content-Disposition","tableprint.pdf");
     response.setContentLength(bytes.length);
     ServletOutputStream ouputStream = response.getOutputStream();
    
     JRPdfExporter pdf=new JRPdfExporter ();
     pdf.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
     pdf.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
     pdf.exportReport();
     ouputStream.write(bytes,0,bytes.length);
     ouputStream.flush();
     ouputStream.close();
     conn.close();
posted on 2008-03-10 22:16 HUIKK 阅读(805) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: