【问题标题】:Firefox 4 & IE9 won't open my generated JasperReports in JSF appFirefox 4 & IE9 不会在 JSF 应用程序中打开我生成的 JasperReports
【发布时间】:2011-08-17 00:30:03
【问题描述】:

我正在开发一个 Java EE 应用程序(JSF 2 + richfaces 3.3.3 + JasperReports 3.7.1 + SSL) 我用 chrome 测试了我的应用程序,它正在工作。 但是使用 Firefox 4(在 Firefox 3 上运行良好)和 IE9,使用 JasperReports 生成的 pdf 不会在新页面中打开:

这是我的代码:

<h:form id="forme2" target="_blank">
                    <h:commandButton
                        id="printBtn"
                        image="../IMAGES/print.png"
                        value="Open PDF"
                        action="#{prtf.openPDF}">
                    </h:commandButton>
</h:form>

public String openPDF() {
        // Prepare.
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
        Connection connection = null;
        try {
            connection = getConnection();

            Map parameters = new HashMap();
            parameters.put("num_cpt", cpt.getNumCpt());

            JasperPrint jasperPrint;
                jasperPrint = JasperFillManager.fillReport(new FileInputStream(new File("C:\\JasperReports\\" + "portefeuille" + ".jasper")), parameters, connection);

            JRPdfExporter exporter = new JRPdfExporter();
            exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, response.getOutputStream());
            response.setContentType("application/pdf");
            response.setHeader("Content-Disposition", "inline;filename=" + cpt.getLibCpt().replace(" ", "_") + "_Portefeuille.pdf");

            exporter.exportReport();

            response.getOutputStream().flush();
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            facesContext.responseComplete();
            try {
                if (connection != null) {
                    connection.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    }

你有什么想法可以解决我的问题吗?

UPDATE1:当我从 h:form 标签中删除属性 target="_blank" 时,它在 IE9 中运行良好,但在 firefox 4 中仍然无法运行

【问题讨论】:

    标签: jsf-2 jasper-reports internet-explorer-9 firefox4


    【解决方案1】:

    在导出前尝试添加以下代码:

    response.setHeader("Pragma", "cache"); response.setHeader("缓存控制", "缓存");

    当我在 IE 中遇到类似问题时,这对我很有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-01
      • 2022-06-15
      • 1970-01-01
      • 2019-07-07
      • 2013-05-01
      • 2020-08-03
      • 1970-01-01
      相关资源
      最近更新 更多