Results 1 to 1 of 1
  1. #1
    sammes is offline Member
    Join Date
    Mar 2009
    Rep Power

    Question Urgent! Strange problem when calling jasper report from STRUTS


    I have a problem when calling a jasper report from Struts and I have no idea what I am doing wrong.

    I get a "java.lang.IllegalStateException: Cannot forward after response has been committed" exception!

    My code is below...
    public ActionForward execute(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException {
    if (irForm.isExcelReport()){
    return mapping.findForward(AbstractBaseReportBean.prepare ReportJrxml(getRatesAndMissingCurrencies(), JASPER_FILE, "EXCEL", request, response));
    } // I pass a list with one map to this "prepareReportJrxml" method

    public static String prepareReportJrxml(List reportData, final String compileFileName, final String _exportOption, final HttpServletRequest request, final HttpServletResponse response) throws JRException, IOException, ReportingException {

    HttpSession session = request.getSession();
    ServletContext context = session.getServletContext();

    ReportConfigUtil.compileReport(context, getCompileDir(), compileFileName);
    File reportFile = new File(ReportConfigUtil.getJasperFilePath(context, getCompileDir(), compileFileName + ".jasper"));
    JasperPrint jasperPrint = ReportConfigUtil.fillReport(reportFile, getReportParameters(), getJRBeanCollectionDataSource(reportData));

    ExportOption option = ExportOption.valueOf(_exportOption);
    if(option == null){
    option = getExportOption();

    if (option.equals(ExportOption.HTML)) {
    exportReportHtml(jasperPrint, response);
    } else if (option.equals(ExportOption.EXCEL)){
    exportReportPlainXls(jasperPrint, response);
    } else if (option.equals(ExportOption.PDF)){
    exportReportPdf(jasperPrint, request, response);
    //FacesContext.getCurrentInstance().responseComplete ();
    return LimexGuiConstants.FWD_SUCCESS;

    exportReportPlainXls method:
    protected static void exportReportPlainXls(JasperPrint jp, HttpServletResponse response) throws JRException, IOException {
    ByteArrayOutputStream xlsReport = new ByteArrayOutputStream();
    JRAbstractExporter jasperXlsExportMgr = new JRXlsExporter();
    jasperXlsExportMgr.setParameter(JRXlsExporterParam eter.JASPER_PRINT, jp);
    jasperXlsExportMgr.setParameter(JRXlsExporterParam eter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
    jasperXlsExportMgr.setParameter(JRXlsExporterParam eter.IS_WHITE_PAGE_BACKGROUND, java.lang.Boolean.FALSE);
    jasperXlsExportMgr.setParameter(JRXlsExporterParam eter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
    jasperXlsExportMgr.setParameter(JRXlsExporterParam eter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
    jasperXlsExportMgr.setParameter(JRExporterParamete r.OUTPUT_STREAM, xlsReport);
    byte[] bytes = null;
    bytes = xlsReport.toByteArray();
    response.setHeader("Pragma", "public");
    response.setHeader("Cache-Control", "max-age=1000");
    response.setHeader("content-Disposition", "attachment;filename="report.xls";");
    ServletOutputStream outputStream = response.getOutputStream();
    InputStream is = new ByteArrayInputStream(bytes);
    int iSize = 0;
    byte[] oBuff = new byte[1024];
    while ((iSize = != -1) {
    outputStream.write(oBuff, 0, iSize);

    at this point I get the error:
    //FacesContext.getCurrentInstance().responseComplete ();
    return LimexGuiConstants.FWD_SUCCESS;

    I dont know how to eliminate this error.
    I think, this is also the reason why no data will be passed to the excel sheet (I think).

    Thanks a lot ! cheers
    Last edited by sammes; 03-04-2009 at 11:08 AM.

Similar Threads

  1. jasper report
    By vidhyaprabu in forum New To Java
    Replies: 6
    Last Post: 11-12-2009, 04:31 AM
  2. jasper report in struts
    By in forum Advanced Java
    Replies: 2
    Last Post: 03-31-2009, 12:30 PM
  3. Error With Sql And Jasper Report
    By Heather in forum JDBC
    Replies: 4
    Last Post: 12-03-2008, 12:31 PM
  4. JSP and Jasper Report in Netbeans 6.1
    By ShatireAzam in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-08-2008, 10:43 AM
  5. Jasper report + JPQL
    By tarat in forum Advanced Java
    Replies: 2
    Last Post: 08-01-2008, 07:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts