
10/02/2009, 05:35
|
| | Fecha de Ingreso: febrero-2009
Mensajes: 1
Antigüedad: 16 años, 1 mes 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!! |