• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Showing PDF in a new window

 
Neo Parker
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What part of Struts prevents you from doing any of this?
 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
create an Action servlet that would generate the PDF then return null.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
M Jiva,
Your post was moved to a new topic.
 
Pravin Shirke
Ranch Hand
Posts: 152
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic