Firefox 4 & IE9 won't open my generated JasperReports in JSF app
i'm developping a Java EE app (JSF 2 + richfaces 3.3.3 + JasperReports 3.7.1 + SSL) i tested my app with chrome, and it's working. But with Firefox 4 (it's working fine with firefox 3) and IE9, the pdf generated with JasperReports won't open in a new page:
this is my codes :
<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;
}
}
Do you have some ideas how to solve my problem ?
UPDATE1: when i removed the attribute target="_blank" from my h:form tag, it worked fine in IE9, but still don't work in firefox 4
Try to add following code prior to exporting:
response.setHeader("Pragma", "cache"); response.setHeader("Cache-Control", "cache");
This magically helped me when I meet similar problems with IE.
链接地址: http://www.djcxy.com/p/89918.html