2013-01-08 46 views
0

我正在使用JR生成PDF發票。在我的本地機器(Linux操作系統Ubuntu)完美的作品:賈斯珀報告未正確在PDF中正確傳輸

FacesContext fc = FacesContext.getCurrentInstance(); 
     ExternalContext ec = fc.getExternalContext(); 
     String templateAbsolutePath = ec.getRealPath(templateRelativePath); 

     JasperReport jasperReport; 
     try { 
      jasperReport = JasperCompileManager.compileReport(templateAbsolutePath);   
      JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, getParametriFattura(fattura), datasource); 

      JasperExportManager.exportReportToPdfStream(jasperPrint, ec.getResponseOutputStream()); 

     } catch (JRException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     fc.responseComplete(); 

然而,當我部署了我的戰爭臨時服務器(Linux操作系統Ubuntu),它表明:

enter image description here

我想這是一個微不足道的問題,但我可以從哪裏開始?

我故意省略配置,系統細節等......因爲我不知道什麼是有用的。

回答

2

您需要明確告訴網頁瀏覽器它是PDF文件,而不是(X)HTML文件。

ec.setResponseContentType("application/pdf"); 

注:這需要設置之前的任何位被寫到響應體

+0

我會試着讓你知道 –