Ver Mensaje Individual
  #5 (permalink)  
Antiguo 10/02/2009, 05:35
brj
 
Fecha de Ingreso: febrero-2009
Mensajes: 1
Antigüedad: 15 años, 2 meses
Puntos: 0
Respuesta: Abrir un archivo en una ventana emergente

Hola,

Si que se puede hacer lo que tú quieres. Yo habro pdf y .doc sin problemas:

File ficheroXLS = new File(strPathXLS);
FacesContext ctx = FacesContext.getCurrentInstance();
FileInputStream fis = new FileInputStream(ficheroXLS);
byte[] bytes = new byte[1000];
int read = 0;

if (!ctx.getResponseComplete()) {
String fileName = ficheroXLS.getName();
String contentType = "application/vnd.ms-excel";
//String contentType = "application/pdf";
HttpServletResponse response =
(HttpServletResponse) ctx.getExternalContext().getResponse();

response.setContentType(contentType);

response.setHeader("Content-Disposition",
"attachment;filename=\"" + fileName + "\"");

ServletOutputStream out = response.getOutputStream();

while ((read = fis.read(bytes)) != -1) {
out.write(bytes, 0, read);
}

out.flush();
out.close();
System.out.println("\nDescargado\n");
ctx.responseComplete();
}



Espero que te sirva de ayuda!!