This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Excel reporting through Jasperreports

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to generate excel reports through Jasperreports in a web application (still in evaluation mode). I have written the following JSP which is supposed to generate the Excel report. But When I run the example, all the garbage (I think, binary form of the report) comes up in the browser. I have set the content type as response.setContentType("appcation/excel"). Then why is it showing in binary form ?
Has anybody use the JAsperreports for excel reporting ina web application before ?
thanks in advance...
application.getRealPath("/WEB-INF/lib/jasperreports-0.5.1.jar") +
System.getProperty("path.separator") +


//ServletOutputStream output = response.getOutputStream();

ByteArrayOutputStream baos = new ByteArrayOutputStream();

JasperDesign jasperDesign = JasperManager.loadXmlDesign("C:/jakarta-tomcat-5.0.16/webapps/jasper-webapp/reports/testReport.xml");

JasperReport jasperReport = JasperManager.compileReport(jasperDesign);

Map parameters = new HashMap();

Connection conn = getConnection();

JasperPrint jasperPrint = JasperManager.fillReport(jasperReport,parameters, conn);

File destFile = new File("C:/jakarta-tomcat-5.0.16/webapps/jasper-webapp/reports/", jasperPrint.getName() + ".xls");

JRXlsExporter exporter = new JRXlsExporter();

//JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
byte[] bytes = null;

bytes = baos.toByteArray();
System.out.println("testing: " + bytes.length);


//response.setHeader("Content-disposition","inline; filename=foobar.xls" );

ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
catch(Exception e)

No holds barred. And no bars holed. Except this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!