This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error Displaying PDF in JSP

 
Saurabh Agrawal
Ranch Hand
Posts: 244
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
response.setContentType("application/pdf");
byte[] array = (byte[]) session.getAttribute("pdfFile");

ServletOutputStream outstream = response.getOutputStream();
outstream.write(array);
outstream.flush();


Any quick help in the matter would be highly appreciable.

Saurabh
 
alban maillere
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

http://<url_to_the_pdf>&dummy=.pdf

Hope it helps
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic