This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JSP and the fly likes Display Pdf Content Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Display Pdf Content" Watch "Display Pdf Content" New topic
Author

Display Pdf Content

raj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 96
hi,
i want to display the content of a pdf file in the browser when requested for a jsp file.i am reading the content of pdf in jsp and using the servletoutput stream i am displaying it. But it is displaying as bytes like 0 1 .... . not the original content.



how to display the original content instead of bytes ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35250
    
    7
JSP pages are not meant to be used to emit binary data. While it's theoretically possible, practical considerations make it unfeasible. Convert the JSP into a servlet, and things should go much smoother.


Android appsImageJ pluginsJava web charts
raj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 96
Hi Ulf,
Thank yo for reply. Using servlet fine.
Even the jsp will convert to a servlet ,why can't a jsp.
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

OutputStream can be get only once.

JSPs are used to send back HTML and it obtain the writer for themselves to send those.

So, If you try to get output stream inside JSP, it will end up in unexepected results or even you end up in exception.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 423
Hi,

Just provide a link to the pdf file from your jsp or use jsp action <jsp:forward .... /> and the rest will do...

You might want to read more on this:

PDF Embedding


And this one talking about the linking method, also elaborate on the commands we can pass to PDF file

Link PDFs From Html



Thanks,

Maki Jav
[ December 07, 2006: Message edited by: Maki Jav ]

Help gets you when you need it!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56204
    
  13

Originally posted by raj baig:

Even the jsp will convert to a servlet ,why can't a jsp.


This article explains why.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35250
    
    7
Originally posted by raj baig:
Even the jsp will convert to a servlet ,why can't a jsp.

Yes, a servlet can do everything a JSP page can. But from that it does not follow that a JSP can do everything a servlet can.
raj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 96
Thank you all

" Help get's you when you need it " ---> True.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 423
Raj baig thanks ;)

Maki Jav
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2300
Originally posted by raj baig:
Even the jsp will convert to a servlet ,why can't a jsp.


jsp's should used only for the view part.More of html.In your case you will not have any html part , rather bytes of pdf would be flushed to the browser.In that case better use an servlet.


Rahul Bhattacharjee
LinkedIn - Blog
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by raj baig:
Even the jsp will convert to a servlet ,why can't a jsp.


At the risk of "beating a dead horse"..
You can also see this entry in our JSP Faq for an answer to this question:
http://faq.javaranch.com/view?IllegalStateException


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display Pdf Content
 
Similar Threads
.jasper report return null values
Jasperreports + Struts
JSP and iReports without database connection
iReport in Struts action
Blank page