Firefox 4和IE9不会在JSF应用程序中打开我生成的JasperReports
我正在开发一个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中运行
尝试在导出之前添加以下代码:
response.setHeader("Pragma", "cache"); response.setHeader("Cache-Control", "cache");
当我遇到与IE类似的问题时,这神奇地帮助我。
链接地址: http://www.djcxy.com/p/89917.html上一篇: Firefox 4 & IE9 won't open my generated JasperReports in JSF app