繁体   English   中英

如何在iframe中显示临时文件?

[英]How to display a temp file in an iframe?

我正在使用Java,Jasper Reports和JSF。 我想生成PDF格式的报告,并可以在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();
    }

}

任何想法,建议将不胜感激

您需要有一个指向您加载到iframe中的PDF的URL 就目前而言,您正在尝试直接从文件系统加载文件。 这意味着您的站点将尝试直接从最终用户的文件系统中加载文件,出于明显的原因,不允许这样做。

在服务器上生成PDF,然后生成指向它的URL。 然后将其设置为iframe源。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM