2013-01-07 17 views
1

我正在使用Java,Jasper Reports和JSF。我想生成一個PDF格式的報告,並可以在iframe這樣的東西中顯示它,因爲在同一頁面上可以將過濾器放入報告等等。即使當我粘貼時,報告也可以作爲臨時文件正確生成瀏覽器中的路徑將顯示正確。但把該路由的iframe我得到以下錯誤:如何在iframe中顯示臨時文件?

Not allowed to load the local resource: file :/// C :/ Users/Juanes ~ 1/AppData/Local/Temp/reportePedidosTemporal1922509630584311367.pdf 

這是我的代碼:

public void prueba(AjaxBehaviorEvent evento) 
{ 
    try 
    { 
     Map<String, Object> parametros = new HashMap<String, Object>(); 
     parametros.put("autor", "Juan Esteban"); 
     parametros.put("titulo", "Reporte de Pedidos"); 

     List<PedidosVO> listaPedidos = new ArrayList<PedidosVO>(); 

     for (int i = 1; i <= 10; i++) 
     { 
       PedidosVO pedido = new PedidosVO(""+i,"Cliente:"+i,(i+1)); 
       pedido.setPuntos(i); 
       listaPedidos.add(pedido); 
     } 

     JasperDesign design = JRXmlLoader.load("C:\\Reportes\\Reporte2Pedidos.jrxml"); 

     JasperReport reporte = JasperCompileManager.compileReport(design); 

     //-**-**-/*-/ 

     JasperPrint jasperPrint = JasperFillManager.fillReport(reporte, parametros,new JRBeanCollectionDataSource(listaPedidos)); 

     byte[] flujo = JasperExportManager.exportReportToPdf(jasperPrint); 
     File tempFile = File.createTempFile("reportePedidosTemporal",".pdf"); 
     System.out.println(tempFile.setReadable(true)); 
     escribirByte(tempFile,flujo); 
     tempFile.deleteOnExit(); 

     if(tempFile.exists()) 
     { 
      System.out.println("RUTA : "+tempFile.getPath()); 
      url = tempFile.getPath(); 
     } 
    } 
    catch(Exception e) 
    { 
     e.printStackTrace(); 
    } 

} 

任何意見,建議,將不勝感激

回答

1

你需要有一個URL指向您加載到iframe中的PDF。就目前而言,您正試圖直接從文件系統加載文件。這意味着您的站點將嘗試直接從最終用戶的文件系統加載文件,這是不允許的,原因很明顯。

在您的服務器上生成PDF,然後生成一個指向它的URL。然後將其設置爲iframe源。

+0

感謝您的回答,我會研究如何做到這一點 –