Jump to content
Changes to the Jaspersoft community edition download ×

Excel reporting in a JSP ( a web based app.)

2005 IR Help

Recommended Posts

By: manish - zmanish

Excel reporting in a JSP ( a web based app.)

2004-01-30 04:39


I am evaluating Jasperreports for last 2 week. Right now, I am trying to use the JAsperreports for excel reporting in a web abased appalication (JSP). I have written the following code. But When I run the application, it throws following error :


JasperReports encountered this error :

dori.jasper.engine.JRException: No output specified for the exporter.

at dori.jasper.engine.export.JRXlsExporter.exportReport(JRXlsExporter.java:241)

at org.apache.jsp.jsp.EXL_jsp._jspService(EXL_jsp.java:119)



The code in JSP page is :







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);




JRXlsExporter exporter = new JRXlsExporter();






exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

//exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());


exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);

//exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);





If I use JRHtmlExporter in place of JRXlsExporter , it works fine.


Please help me out as I am not able to understand whether it is limitation of JAsperreports (for Excel reporting) or something else which I am missing terribly...Also, I would like to seek your comment on the usability of Jasperreports for Excel repeorting in a web based application.









By: Teodor Danciu - teodord

RE: Excel reporting in a JSP ( a web based ap

2004-01-30 07:10




Use the OUTPUT_STREAM parameter and not the



Ouput to the response.getOutputStream().



I hope this helps.







By: manish - zmanish

RE: Excel reporting in a JSP ( a web based app.)

2004-02-02 20:57

Hi Teodar,

I have changed the code according to your advice as :

exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, response.getOutputStream());


But now I am getting this error :

java.lang.IllegalStateException: getOutputStream() has already been called for this response org.apache.coyote.tomcat5.CoyoteResponse.getWriter(CoyoteResponse.java:611)



I am trying to run this example in Tomcat 5 with JDK 1.4 latest version.









By: manish - zmanish

RE: Excel reporting in a JSP ( a web based app.)

2004-02-03 02:13


I am able to remove the above error (java.lang.IllegalStateException) by removing white space in the JSP file.

Now , I have writtem the code this way :


JRXlsExporter exporter = new JRXlsExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

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);


ServletOutputStream ouputStream = response.getOutputStream();




ouputStream.write(bytes, 0, bytes.length);




When I run this example, I got the binary data in the browser. Why is it so ? I have set the contenttype as response.setContentType("application/excel"); Why is it displaying the result in binary form ?


I really need your help in this regard. I am really wondering if I can use JasperReports for excel reporting for web application.




Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...