Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display Pdf Content

 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maki Jav
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by raj baig:

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


This article explains why.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all

" Help get's you when you need it " ---> True.
 
Maki Jav
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj baig thanks ;)

Maki Jav
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic