Java 如何在iframe中显示临时文件?
我正在使用Java、Jasper Reports和JSF。我想生成一份PDF格式的报告,并可以在类似这样的Java 如何在iframe中显示临时文件?,java,jsf,jasper-reports,Java,Jsf,Jasper Reports,我正在使用Java、Jasper Reports和JSF。我想生成一份PDF格式的报告,并可以在类似这样的iframe中显示它,因为在同一页面上可以对报告进行筛选等等。。即使在浏览器中粘贴路径时,报告也会正确生成为临时文件,并显示为正确。但要将该路由放入iframe,我会得到以下错误: Not allowed to load the local resource: file :/ / / C :/ Users / Juanes ~ 1/AppData/Local/Temp/reportePedi
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();
}
}
public void prueba(AjaxBehaviorEvent事件)
{
尝试
{
Map parametros=newhashmap();
参数put(“autor”、“Juan Esteban”);
参数设置(“titulo”、“Pedidos报告”);
List listaPedidos=new ArrayList();
对于(int i=1;i,您需要有一个指向加载到iframe中的PDF的URL。目前,您正在尝试直接从文件系统加载文件。这意味着您的站点将尝试直接从最终用户的文件系统加载文件,这是不允许的,原因很明显
在服务器上生成PDF,然后生成指向它的URL。然后将其设置为iframe源。您需要有一个指向加载到iframe中的PDF的URL。目前,您正试图直接从文件系统加载文件。这意味着您的站点将尝试从最终用户的文件系统加载文件由于明显的原因,不允许直接使用阀杆
在您的服务器上生成PDF,然后生成指向它的URL。然后将其设置为iframe源。谢谢您的回答,我将研究如何执行此操作谢谢您的回答,我将研究如何执行此操作