我的xhtml是
<h:form id="ibForm">
<p:commandButton value="Yazdır" ajax="false" action="#{islemiBitenlerBean.run_Rpr('PDF')}" icon="ui-icon-print" immediate="true"/>
</h:form>
Backing bean是(会话范围)
public void run_Rpr(String tip) throws IOException, JRException, ClassNotFoundException, SQLException {
HashMap m = new HashMap();
m.put("belgeNo", selectedBelge.getBelgeNo());
reports.preparetReport(RaporTuru.PDF, "reports//rapor//onaybelgesi.jrxml", "Onay Belgesi", m);
}
我的preparetReport方法是
public void preparetReport(RaporTuru tur, String filePath, String fileName, HashMap jasperParameter) throws JRException, IOException, ClassNotFoundException, SQLException {
Connection connection;
Class.forName("oracle.jdbc.OracleDriver");
connection = DriverManager.getConnection("jdbc:oracle:thin:@--------", "----", "******");
JasperReport jasperReport;
JasperReport jasperReportSub;
JasperPrint print;
FacesContext faces = javax.faces.context.FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse();
ServletContext servletContext = (ServletContext) faces.getExternalContext().getContext();
String jrxmlFile = servletContext.getRealPath("/") + filePath;//raporumuzun yolu
JasperDesign jasperDesign = JRXmlLoader.load(jrxmlFile);
jasperReport = JasperCompileManager.compileReport(jasperDesign);
print = JasperFillManager.fillReport(jasperReport, jasperParameter, connection);
byte[] outData = JasperExportManager.exportReportToPdf(print);
ByteArrayOutputStream rrtReport = new ByteArrayOutputStream();
ServletOutputStream out = null;
switch (tur) {
case PDF:
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".pdf");
response.getOutputStream().write(JasperExportManager.exportReportToPdf(print));//web sayfamızdan raporu çıkarttık
faces.responseComplete();
break;
}
但我必须点击两次才能下载PDF。 有任何建议只需点击一下即可下载吗?