• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Display Pdf Content

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67590
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

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
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all

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

Maki Jav
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic