• Jasperreport5.6.9-----2


    Jasperreport5.6.0生成PDF
     
    上一篇讲的是jasperreport5.6.0生成pdf,运行后可以生成pdf,可是和我们的需求有点差距,我们是要求生成后,可以直接打开或保存,这就需要response的设置了,如下代码:

       //ireport生成项目立项PDF格式

       public String getIreportPDFAction()

       {

          Connection conn =null;//连接

          try {

             String projectapproid =request.getParameter("projectapproid");

              ////连接JDBC得到数据URL

              String url ="jdbc:oracle:thin:@192.168.1.104:1521:orcl";

              Class.forName("oracle.jdbc.driver.OracleDriver");

              conn = DriverManager.getConnection(url,"zwjx","zwjx");

              //设置参数

              Map parmerters = new HashMap();

              parmerters.put("projectapproid", projectapproid);

             //读取报表模板文件

             FilejasperFile=new File("D:/Workspaces/zwjxSystem/WebRoot/jasper/report1.jasper");

             //设置报表中参数的值

             Map map =new HashMap();

             map.put("projectapproid", projectapproid);

              //输出流

              OutputStream ous =response.getOutputStream();

              //输出文件名

              String filenames="项目立项";

              //打印

              JasperPrint print =JasperFillManager.fillReport(jasperFile.getPath(), map,conn);

    //        //生成pdf

              JRAbstractExporter exporter =newJRPdfExporter();

              response.reset();

              response.setContentType("application/pdf");

              response.setHeader("Content-Disposition","attachment;filename="+new String(filenames.getBytes("gbk"),"iso8859-1")+".pdf");

              //指向

              JasperReportsUtils.render(exporter, print,ous);

              ous.flush();

              ous.close();

          }catch (Exceptione) {

              e.printStackTrace();

              System.out.println("ireport生成报表出错!");

          }finally

          {

              try {

                 conn.close();

              }catch(SQLException e) {

                 //TODO Auto-generated catch block

                 e.printStackTrace();

              }

          }

              returnnull;

       }

    运行后,弹出如下对话框,我们可以根据需要选择。可以直接打开,也可以保存。

  • 相关阅读:
    Spring jar包功能
    maven pom.xml详细介绍,必须留一份
    redis基本类型以及优点特性
    如何实现网站的防盗链?
    php几种常见排序算法
    批量去除文件的BOM头
    Keepalived实现双机热备
    nginx配置文件详解
    源码编译安装lnmp环境
    nginx实现https网站设置
  • 原文地址:https://www.cnblogs.com/UUUz/p/9365084.html
Copyright © 2020-2023  润新知