创建后应下载jasper报告 [英] jasper report should download after creating

查看:80
本文介绍了创建后应下载jasper报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我正在使用本地驱动器中的jasper报告和.jxml文件
(例如C:/jrxml/idcard.jrxml),现在我希望它与项目放在一起,并且应在生成时下载.
有人请建议我该怎么办?

Here i am using jasper report and .jxml file using from local drive
(like C:/jrxml/idcard.jrxml),now i want it to put with project and that should download when it generate.
anyone please suggest me what to do?

public void generateReport() {

        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bsaigsamed?user=root&password=root");

            InputStream input = new FileInputStream(new File("C:/jrxml/idcard.jrxml"));
            JasperDesign jasperDesign = JRXmlLoader.load(input);

            JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);


            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);

            //Exporting the report
            OutputStream output = new FileOutputStream(new File("D:/Report/Reperesentative_id.pdf"));
            JasperExportManager.exportReportToPdfStream(jasperPrint, output);


            System.out.println("Report Generation Complete");
            conn.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (JRException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

推荐答案

将其扔到操作系统上,然后让操作系统决定如何打开它.这很容易,免维护并且是常见的方法.

throw it against the OS and let the OS decide on how to open it. That''s easy, maintenance free and the common way.

final Program p = Program.findProgram("pdf");
p.execute(printFilePath);



然后,用户可以决定是否要使用它(例如打印它)或保存它.



The user can then decide if he wants to work with it (e.g. print it) or save it.


这篇关于创建后应下载jasper报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆