File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » JSP
Bookmark "Error Displaying PDF in JSP" Watch "Error Displaying PDF in JSP" New topic
Author

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");
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


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

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

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

Hope it helps


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

Joined: Jan 10, 2002
Posts: 60059
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error Displaying PDF in JSP
 
Similar Threads
getting error while displaying PDF from jsp
Pdf opens blank in browser
JSp Output to PDF
Response as PDF
Open a VCalendar file on the fly