View report using JasperViewer or something else i

2019-01-26 01:01发布

I'm new to JasperReports and I want to get report preview using JasperViewer in web application.

Is this possible or any other viewing method in web application (without PDF and XLSX)?

1条回答
We Are One
2楼-- · 2019-01-26 01:43

You can export to html file then you can send it as output or ServletOutputStream , show it in a frame

String htmlpath="E:/JASPER/OUTPUT/test_jasper.html";
 JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
       JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
       JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
        JasperExportManager.exportReportToHtmlFile(jasperPrint,htmlpath);
        InputStream in=new FileInputStream(htmlpath);
        int len = -1;
        byte[]  byt = new byte[1024];

        ServletOutputStream outputStream = response.getOutputStream();
        while((len = in.read(byt)) != -1){
            outputStream.write(byt, 0, len);
        }
        outputStream.flush();
        outputStream.close();
查看更多
登录 后发表回答