This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JSP and the fly likes Error Displaying PDF in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Error Displaying PDF in JSP" Watch "Error Displaying PDF in JSP" New topic

Error Displaying PDF in JSP

Saurabh Agrawal
Ranch Hand

Joined: Oct 07, 2003
Posts: 244
Hi guys,

I am trying to read contents of PDF from the database as bytearray. Then i am simply flusing the bytearray on the JSP page. I have a link on the JSP page which when clicked should open the PDF file.

When i am clicking the link, it is showing some garbled content in the Internet Explorer. While i am trying to open the same link in the Firefox and it is working perfectly fine.

I have seen some solutions on google but doesnt seem to work.

My code is as follows:
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Pragma", "No-cache");
byte[] array = (byte[]) session.getAttribute("pdfFile");

ServletOutputStream outstream = response.getOutputStream();

Any quick help in the matter would be highly appreciable.


Success is not doing extraordinary things but doing ordinary things extraordinarily well.
alban maillere

Joined: Nov 06, 2006
Posts: 6
i didn't really get how you managed to output a pdf directly from the jsp, but however

it's a kinda usual problem with IE. It chooses what to to whith response based on its extension rather than the mime type.

try just adding cheating parameter at the end of the url of the PDF


Hope it helps

while(true){<br /> this.put(BeerFactory.newInstance());<br />}
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63869

JSP is an astoundingly poor choice for displaying anything but text content. Switch to a servlet for this.

Perhaps this article will help explain why.
[ November 06, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Error Displaying PDF in JSP
It's not a secret anymore!