Java Servlet not displaying PDF/ZIP files correctly in IE

P

Paul Jacobs

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
 
D

Darren Davison

Paul said:
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,
 
P

Paul

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
 
N

Neomorph

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 said:
this may be of use to you: <http://www.lowagie.com/iText/faq.html#msie>

Regards,

Cheers.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top