Boa tarde pessoal, estou fazendo um relatório, e salvando em disco (relatório XLS), porém gostaria
que o usuario fizesse download do mesmo, tipo não salvar em disco e sim pedir para fazer o download,
como posso fazer isso?
Você poderá adaptá-lo a sua aplicação, espero que ajude.
J
Java_Terminator
Baum pessoal, consegui fazer aqui. Obrigado a todos…
Segue o código abaixo:
JRBeanCollectionDataSourcedados=newJRBeanCollectionDataSource(lista);//LISTA COM OS OBJETOSjava.net.URLresource=this.getClass().getClassLoader().getResource("../../relatorio/Relatorio.jasper");InputStreamis=newFileInputStream(resource.getFile());Mapparameters=newHashMap();byte[]bytes=null;JasperPrintjasperPrint=JasperFillManager.fillReport(is,parameters,dados);StringnomeRelatorio="relatorioTeste";response.setContentType("application/x-download");response.setHeader("Content-Disposition","attachment; filename="+nomeRelatorio+".xls");JRXlsExporterexport=newJRXlsExporter();OutputStreamoutput=response.getOutputStream();export.setParameter(JRXlsExporterParameter.JASPER_PRINT,jasperPrint);export.setParameter(JRXlsExporterParameter.OUTPUT_STREAM,output);export.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE,Boolean.TRUE);export.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE);export.setParameter(JRXlsExporterParameter.MAXIMUM_ROWS_PER_SHEET,Integer.decode("65000"));export.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE,Boolean.TRUE);export.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND,Boolean.FALSE);export.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE);export.exportReport();output.flush();output.close();