I'm using IText 1.3 to generate PDF reports on-the-fly in my Struts-based web application.  Occasionally, I see the following error:

      Error 500: Server caught unhandled exception from servlet [SimpleFileServlet]: Response already committed.

This only happens when the application is running on a Linux-based instance of Websphere (my production environment), and not consistently.  It never seems to happen when running on a Windows-based instance of JOnAS (my development environment).  I've seen one other post on this mailing list regarding this type of error, but that person's problem and solution did not seem to apply in my case.  My problem may result from the way I'm implementing the PDF generation.  Here are the specifics...

I have a JSP page with a few controls on it for selecting report criteria.  When a button is clicked, the form is submitted, calling methods in my action class to generate the report content and display it in a pop-up window.

struts-config.xml contains these forward declarations for the report criteria page:

      <forward name="getReport" path="report.td" />
      <forward name="displayReport" path=" reportOutput.td" />

All the "getReport" method does is save the updated form bean in session, with a viewReport flag set to true.  It then redisplays the report criteria page, which checks the flag.  If it's true, then the pop-up window is opened using this URL:

      report.do?method=viewReport

That fires the viewReport method in my action class, which builds up the PDF content like this:

        // Generate PDF
        Document document = new Document( PageSize.LETTER.rotate(), 20, 20, 60, 50 );
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance( document, baos );
        PageHandler pageHandler = this.new PageHandler( bean, messageResources, locale );
        writer.setPageEvent( pageHandler );

        document.open();

        (content generated and added to the document)

        document.close ();        
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader ("Pragma", "public");
        // Content type
        response.setContentType("application/pdf");
        // Contentlength is needed for Internet Explorer
        response.setContentLength (size);
        // write ByteArrayOutputStream to the ServletOutputStream
        ServletOutputStream out = response.getOutputStream();
        baos.writeTo(out);
        out.flush();

        return mapping.findForward ( "displayReport" );

tiles-defs.xml contains an empty tile definition, just so that the "displayReport" action mapping has something to point to:

    <definition name="reportOutput.td "/>

Maybe that's part of the problem, but I don't know.  Is there a simpler, more straightforward way to do this?  The key is that I must submit the form (to get the report selection criteria) and the report output has to be displayed in its own window.  If anyone can provide me with some clues, I'd appreciate it.

Thanks.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to