I thought I would add some more information to my original post:

I have found that if I remove the setContentType("application/pdf") line of
code, then IE does not generate the request 2 times (only once).  However,
this doesn't have the desired effect, because when the browser receives the
byte stream, it will prompt the user as to what to do with the file that is
being downloaded, instead of simply displaying the PDF in the Adobe plug-in
as it will do when I set content type to "application/pdf".

Again, any help is greatly appreciated.

Thanks,
Mark

----- Original Message -----
From: "Mark Gilmore" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, March 31, 2003 5:47 PM
Subject: Servlet PDF Streaming


> Hello,
>
> I have a servlet that generates a PDF.
> Whenever I request the Servlet from my browser (IE 6.0) the Servlet always
> get invoked 2 times.
> I found some mention of this on a Google Groups search, but the suggested
> remedy did not work.
>
> Here is the code from my servlet:
>
> . . .
>
>  public void service(HttpServletRequest request, HttpServletResponse
> response)
>   throws ServletException, IOException
>  {
>
>   if (request.getHeader("user-agent").equals("contype"))
>   {
>       response.setContentType("application/pdf");
>       return;
>   }
>
>   iCntr++;
> System.out.println("Servlet Call #" + iCntr);
>
>   HttpSession session = request.getSession(true);
>
>
>   HashMap refData = null;
>   Hashtable chartImages = null;
>
>   if (session != null)
>   {
>
>       response.setContentType("application/pdf");
>    response.setHeader("Pragma", "no-cache");
>    response.setHeader("Cache-Control", "no-cache");
>
>    refData = (HashMap)session.getAttribute("refData");
>    chartImages = (Hashtable)session.getAttribute("chartImages");
>
>    boolean bIncludeSummaryGraph = false;
>    boolean bIncludeIndividualGraph = false;
>
>    // Get Parameters. . .
>
>    // Optional user-specified title for document
>    String sReportTitle = request.getParameter("reportTitle");
>
>    String sCurrency = request.getParameter("currency");
>
>    // Find out which type of graphs the user wants on his/her PDF
>    String sGraphType = request.getParameter("graphType");
>
>    if (sGraphType == null)
>    {
>        sGraphType = "both";
>    }
>
>    if (sGraphType.equalsIgnoreCase("individual"))
>    {
>        bIncludeIndividualGraph = true;
>    }
>    else if (sGraphType.equalsIgnoreCase("both"))
>    {
>        bIncludeSummaryGraph = true;
>        bIncludeIndividualGraph = true;
>    }
>    else
>    {
>        // Default to showing summary
>        bIncludeSummaryGraph = true;
>    }
>
>    ByteArrayOutputStream baos = null;      // The PDF Byte Output Stream
>    PDFChartGenerator pdfGenerator = new PDFChartGenerator();
>
>
>    try
>    {
>     //create context variable for use in pages
>     matrix.db.Context context = Framework.getFrameContext(session);
>
>     baos = pdfGenerator.generateDocument(context, chartImages, refData,
> bIncludeSummaryGraph, bIncludeIndividualGraph,
> request.getHeader("Accept-Language"), sReportTitle, sCurrency);
>
>    }
>    catch (Exception e)
>    {
>     e.printStackTrace();
>     throw new ServletException("Exception Occurred:  " + e.getMessage());
>    }
>
>    ServletOutputStream out = null;
>
>       out = response.getOutputStream();
>
>    response.setContentLength(baos.size());
>
>    baos.writeTo(out);
>
>    out.flush();
>    out.close();
>   }
>
> How can I avoid having the servlet invoked multiple times from IE?
> Any help is greatly appreciated.
>
> Thanks,
> Mark
>
>
> --
> Mark Gilmore
> Spry Technology, Inc.
> [EMAIL PROTECTED]
>
>




-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb: 
Dedicated Hosting for just $79/mo with 500 GB of bandwidth! 
No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to