我正在开发一个 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 中仍然无法运行