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 Display Pdf Content Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
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: 41587
    
  54
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.


Ping & DNS - my free Android networking tools app
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: 435
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: 61071
    
  66

Originally posted by raj baig:

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


This article explains why.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41587
    
  54
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: 435
Raj baig thanks ;)

Maki Jav
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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
 
Don't get me started about those stupid light bulbs.
 
subject: Display Pdf Content