Java Servlet not displaying PDF/ZIP files correctly in IE

Discussion in 'Java' started by Paul Jacobs, Aug 23, 2003.

  1. Paul Jacobs

    Paul Jacobs Guest

    We have had a Java servlet running in a production web application for
    a few years that will read a PDF, text, or zip file located outside
    the scope of the web site (Note: this is running on solaris).
    Everything was working great until the spring when Microsoft started
    releasing a ton of security patches for both IE and windows.

    Text files are still working, but users can no longer view the ZIP or
    PDF files within IE. Depending on which patches the user has applied
    to their computers, when trying to view a pdf inside IE their will be
    a white screen in IE, acrobat will start and give some errors, and
    other similar variations. For the zip files, Winzip will start up and
    you can see in the status bar that it is downloading the file, but
    when it finishes you have an empty zip.

    If users save the files to their computers or network, they can open
    the zips or pdfs without any problems. The servlet must be streaming
    the binary data fine if it saves properly to a filesystem, but there
    must be something that is throwing IE off.

    Here is a snippet of code from the servlet using a PDF as an example.
    Any help would greatly be appreciated. Most of our users are on IE 6.
    I think everything works fine in Netscape 6.2, but haven't tried
    other versions or Mozilla.

    servet code:

    File f = new File("/reports/report.pdf");

    response.setContentType("application/pdf") ;
    response.setHeader("Content-Disposition", "inline;
    filename=report.pdf");

    //I have tried it with and without the next two lines of code
    //if this is not the proper way to determine content length,
    //please post the correct code
    int length = (int)(f.length());
    response.setContentLength(length);

    FileInputStream fis = null;
    try{
    fis = new FileInputStream(f);
    //OutputStream out;
    DataOutputStream outputStream = new
    DataOutputStream(response.getOutputStream());
    byte[] buf = new byte[4 * 1024]; // 4K buffer
    int bytesRead;
    while ((bytesRead = fis.read(buf)) != -1) {
    outputStream.write(buf, 0, bytesRead);
    }
    } finally {
    if (fis != null) fis.close();
    }

    Thanks.
    Paul
    Paul Jacobs, Aug 23, 2003
    #1
    1. Advertising

  2. Paul Jacobs wrote:

    > Text files are still working, but users can no longer view the ZIP or
    > PDF files within IE. Depending on which patches the user has applied
    > to their computers, when trying to view a pdf inside IE their will be
    > a white screen in IE, acrobat will start and give some errors, and
    > other similar variations.


    this may be of use to you: <http://www.lowagie.com/iText/faq.html#msie>

    Regards,

    --
    darren@ public key
    davison|uk.net www.davison.uk.net/key.jsp
    Darren Davison, Aug 23, 2003
    #2
    1. Advertising

  3. Paul Jacobs

    Paul Guest

    Thanks, but I am not sure how much that is going to help. The link you gave
    me mostly is talking about dynamically generating a PDF in a ByteArray and
    displaying it. In my case the PDFs already exist, so instead of reading
    from a ByteArray I am reading from a file.

    Anyone else have any idea on how to fix the issue I am having with the
    servlet?

    Paul

    "Darren Davison" <> wrote in message
    news:3f47e339$0$190$...
    > Paul Jacobs wrote:
    >
    > > Text files are still working, but users can no longer view the ZIP or
    > > PDF files within IE. Depending on which patches the user has applied
    > > to their computers, when trying to view a pdf inside IE their will be
    > > a white screen in IE, acrobat will start and give some errors, and
    > > other similar variations.

    >
    > this may be of use to you: <http://www.lowagie.com/iText/faq.html#msie>
    >
    > Regards,
    >
    > --
    > darren@ public key
    > davison|uk.net www.davison.uk.net/key.jsp
    Paul, Aug 24, 2003
    #3
  4. Paul Jacobs

    Neomorph Guest

    On Sun, 24 Aug 2003 16:21:01 GMT, "Paul" <>
    two-finger typed:

    >Thanks, but I am not sure how much that is going to help. The link you gave
    >me mostly is talking about dynamically generating a PDF in a ByteArray and
    >displaying it. In my case the PDFs already exist, so instead of reading
    >from a ByteArray I am reading from a file.


    Then you missed the part about making sure that the headers that are sent
    back by the Servlet contain the exact length of that file ?

    I read the comments on the page referred, and it looks like a missing or
    inaccurate Content-length header can keep MSIE from displaying the PDF file
    properly.

    >
    >Anyone else have any idea on how to fix the issue I am having with the
    >servlet?


    The solution was right there.

    >
    >Paul
    >
    >"Darren Davison" <> wrote in message
    >news:3f47e339$0$190$...
    >> Paul Jacobs wrote:
    >>
    >> > Text files are still working, but users can no longer view the ZIP or
    >> > PDF files within IE. Depending on which patches the user has applied
    >> > to their computers, when trying to view a pdf inside IE their will be
    >> > a white screen in IE, acrobat will start and give some errors, and
    >> > other similar variations.

    >>
    >> this may be of use to you: <http://www.lowagie.com/iText/faq.html#msie>
    >>
    >> Regards,
    >>
    >> --
    >> darren@ public key
    >> davison|uk.net www.davison.uk.net/key.jsp

    >


    Cheers.
    Neomorph, Aug 25, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Régis Soares

    zip files and pdf files

    Régis Soares, Jun 3, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    465
    Steve C. Orr [MVP, MCSD]
    Jun 3, 2005
  2. circuit_breaker
    Replies:
    2
    Views:
    1,984
    Jack Jia
    Apr 4, 2004
  3. Alex Hunsley
    Replies:
    1
    Views:
    588
    Andrew Thompson
    Sep 16, 2004
  4. MoshiachNow
    Replies:
    2
    Views:
    260
    Ilya Zakharevich
    Oct 4, 2006
  5. Bo Yang
    Replies:
    9
    Views:
    290
    -berlin.de
    Nov 20, 2006
Loading...

Share This Page