• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Error Displaying PDF in JSP

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67665
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic