Yes, I have also seen this on my servlets which
generate PDF reports of 10-15 pages or more. For small
PDF reports like 1-5 pages I havent seen this issue.
-Chetan
--- Alex Amies <[EMAIL PROTECTED]> wrote:
> I have a problem with a servlet, which serves up pdf
> documents,
> invoking the servlet twice for every time I request
> the
> url using my browser. The pdf document is produced
> correctly in both instances. Anybody else seen this
> problem, know what it is, or have a constructive
> suggestion?
>
> The servlet gets data from a database, formats into
> xml,
> transforms it with Xalan, then again to a pdf,
> sending
> the content to a byte array where it is then written
> to
> the output stream. Here is a code fragment:
>
> Writer writer = new StringWriter();
>
> // Get an xslt processor factory
> TransformerFactory tFactory =
> TransformerFactory.newInstance();
>
> // Create the 3 objects the XSLTProcessor needs to
> perform the
> transformation.
> ReportInfo reportInfo = getReportData(request,res);
> String xml = reportInfo.getXml();
> StringReader stringReader = new StringReader(xml);
> Source xmlSource = new StreamSource(stringReader);
> Source xslSheet =
> getXSLInput(reportInfo.getReportNo());
> StreamResult xmlResult = new StreamResult(writer);
>
> Transformer transformer =
> tFactory.newTransformer(xslSheet);
>
> // Perform the transformation.
> transformer.transform(xmlSource, xmlResult);
>
> // send output from xsl transformation to a string
> reader
> // create a input source containing the xsl:fo file
> which can be fed to
> Fop
> Reader reader = new StringReader(writer.toString());
> writer.flush();
> writer.close();
>
> //set Driver methods to start Fop processing
> Driver driver = new Driver();
>
>
driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer",".14");
>
driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
>
driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
>
driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
>
driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");
>
> // send pdf writer output to a byte array stream
> ByteArrayOutputStream baos = new
> ByteArrayOutputStream();
> PrintWriter printWriter = new PrintWriter(baos);
> driver.setWriter(printWriter);
> driver.buildFOTree(parser, new InputSource(reader));
> driver.format();
> driver.render();
>
> // send the bytes out to the servlet output stream
> res.setContentType("application/pdf");
> res.setContentLength(baos.size());
>
> long sixty = System.currentTimeMillis() + 60*1000;
> res.setDateHeader("Expires", sixty);
> baos.writeTo(res.getOutputStream());
> res.flushBuffer();
>
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, email:
> [EMAIL PROTECTED]
>
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]