Mezcla de Código Fuente en archivo Excel
Publicado por Hoham (1 intervención) el 03/09/2008 01:59:02
Quiero descargar un archivo en formato xls, el problema no es como hacerlo, ya he intentado con POI, JASPER y algunas otras, pero el resultado siempre es el mismo, el archivo generado además de mi contenido tiene todo el codigo fuente de la página JSP donde se hace la petición de descarga del archivo, alguien sabe porque? el código que utilizo el siguiente:
.............
FacesContext ctx = FacesContext.getCurrentInstance();
ExternalContext ectx = ctx.getExternalContext();
JRDataSource dataSource = ......
InputStream inputStream = ectx.getResourceAsStream(parametro);
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(inputStream);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,new HashMap(), dataSource);
JRXlsExporter exporter = new JRXlsExporter();
ByteArrayOutputStream xlsReport = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, xlsReport);
exporter.exportReport();
byte[] bytes2 = xlsReport.toByteArray();
response.setContentType("application/vnd.ms-excel");
response.setContentLength(bytes2.length);
response.setHeader("Content-disposition", "attachment; filename=""
+ "MI_EXCEL_JR" + ".xls"");
ServletOutputStream outputStream = response.getOutputStream();
outputStream.write(bytes2, 0, bytes2.length);
outputStream.flush();
outputStream.close();
..................
si lo realizo con POI o alguna otra API, el resultado es el mismo, alguien tiene alguna idea del porque pasa esto???
.............
FacesContext ctx = FacesContext.getCurrentInstance();
ExternalContext ectx = ctx.getExternalContext();
JRDataSource dataSource = ......
InputStream inputStream = ectx.getResourceAsStream(parametro);
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(inputStream);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,new HashMap(), dataSource);
JRXlsExporter exporter = new JRXlsExporter();
ByteArrayOutputStream xlsReport = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, xlsReport);
exporter.exportReport();
byte[] bytes2 = xlsReport.toByteArray();
response.setContentType("application/vnd.ms-excel");
response.setContentLength(bytes2.length);
response.setHeader("Content-disposition", "attachment; filename=""
+ "MI_EXCEL_JR" + ".xls"");
ServletOutputStream outputStream = response.getOutputStream();
outputStream.write(bytes2, 0, bytes2.length);
outputStream.flush();
outputStream.close();
..................
si lo realizo con POI o alguna otra API, el resultado es el mismo, alguien tiene alguna idea del porque pasa esto???
Valora esta pregunta


0