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;

    //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());

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

    Paul Jacobs, Aug 23, 2003
    1. Advertisements

  2. this may be of use to you: <>

    Darren Davison, Aug 23, 2003
    1. Advertisements

  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

    Paul, Aug 24, 2003
  4. Paul Jacobs

    Neomorph Guest

    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
    The solution was right there.
    Neomorph, Aug 25, 2003
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.