• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Showing PDF in a new window

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Websphere to deploy my app. My application is Struts-JSP.

Now, I have a PDF in the form of byte stream in my Action. I want to pass this byte stream to the JSP, and have a new window popped up showing the PDF. I don't want to store it as a physical file in the server context or at the client side. Is it possible? If not, what is the best way to achieve this (showing the PDF).

Thank you very much in advance!
 
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
I generally do this sort of thing 'the other way around'.
I build a JSP page that has a link to the servlet that streams the PDF.

Remember, you can't send both binary data (PDF) and text (HTML) in the same response.
 
Neo Parker
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But I can store the byte stream as a Form attribute and access it in the JSP right? If it is a Servlet, I will just send the byte stream in the response.

Since this is struts and jsp, I want to access the byte stream in the jsp using the attribute, and then show a new window with the PDF.
 
Ben Souther
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 Neo Parker:
But I can store the byte stream as a Form attribute and access it in the JSP right?



I'm not sure what you mean by this.
 
Sheriff
Posts: 67750
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
No, you can't.

What you should do is to place Javascript in the JSP which will cause a redirect to occur to a servlet that streams the PDF. By setting the content-type and content-disposition correctly (search this forum for these terms) the response should cause the download box to pop up and then the PDF can be shown in its own viewer.

Having the bytes of the PDF available in the JSP is useless to you.
 
Neo Parker
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your responses. Your idea would definitely work.

But the thing is, we have ActionServlet to handle everything. That's the whole point of Struts, having just one controller. So for just one functionality (showing PDF), I am really hesitant to add one separate servlet.

Isn't there a way to show PDF using just struts, jsp and javascript (without no extra servlet)?
 
Bear Bibeault
Sheriff
Posts: 67750
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
What part of Struts prevents you from doing any of this?
 
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
create an Action servlet that would generate the PDF then return null.
 
Bear Bibeault
Sheriff
Posts: 67750
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
M Jiva,
Your post was moved to a new topic.
 
Ranch Hand
Posts: 152
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Neo,
In struts ActionServlet is the default Controller. you are right till here, but you can create your our controller's extending one of Action,DispatchAction etc. please search for it, and create a servlet or CustomAction to generate the pdf. which you can call using javascript from your jsp.
Hope this helps

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic