Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display a pdf in another jsp

 
fer ribeirao
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a button in JSP (I'm using frameset with jsp). The button when pressed, directs the request (Ajax) to a servlet. The servlet receives the request, loads the PDF and forwards the pdf to another jsp. How do this?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajax is not an appropriate technology for this. You want to return thee PDF response to the browser, not your script.
 
fer ribeirao
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks. But what I wonder is how servlet can receive a request via jsp and return, for example, a pdf file to a different jsp.
 
Anthony Accioly
Greenhorn
Posts: 18
IntelliJ IDE Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my example code at A Previous Code Ranch Post for a base implementation.
Replace content type with within line 21.
Replace line 24 with the following:
You only need to close the first stream at line 44. All of the others close method calls are redundant.
If you are receiving the file location via http parameters like don't forget to write some cleaning code for that (you really don't want to give access to every single file at that server).
If you hit some performance problems (I Hit with 200+ concurrent users) you can also try NIO API and some caching (check out Java Caching System).

Cheers
 
fer ribeirao
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Anthony his help was important! But my problem still remains: I have a jsp named, for example, jspex1.jsp. The jspex1 sends a request to a servlet. The servlet loads a pdf file and sends it to another jsp, named, for example, jspex2.jsp.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes no sense.

What do you mean by "it sends it to another JSP"? Responses aren't sent to JSPs, they are sent to the browser.
 
fer ribeirao
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following code:

<frameset rows="10%,*">
<frame src="principalfr1.jsp" name="principalfr1.jsp" scrolling="no">
<frameset cols="20%,*">
<frame src="jspex1.jsp" name="jspex1">
<frame src="jspex2.jsp" name="jspex2">
</frameset>
</frameset>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesn't shed any light on what you are trying to accomplish.
 
Anthony Accioly
Greenhorn
Posts: 18
IntelliJ IDE Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fer.
I Think what you really meant is that you want the PDF Content from the Servlet to be displayed inside a JSP Page isn't it?
The Servlet should not "redirect" it's content for the JSP, the client (JSP, HTML or any other view technology) should request the content from the Servlet.
Since you are using frames, you can accomplish that by using links with targets. What I mean is that your page jspex1.jsp should have a link for the Servlet URL (/RenderServlet?filename="bla.pdf") targeting jpex2 frame.
See if this helps': HTML Frames Tutorial. take a Look at the syntax.
And Bear, sorry for my PM, looks like we are back at a Client Side question after all .
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to tell because what the original poster wants to do is not being clearly explained.
 
Anthony Accioly
Greenhorn
Posts: 18
IntelliJ IDE Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Out of Topic: I keep hitting the Submit Button thinking I'm hitting "Preview" lol
 
fer ribeirao
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excuse me if I did not understand, but it would be easier if I could explain in Portuguese!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We understand the language problem. Which is why we ask for clarification is something is hard to understand. Try explaining what you mean by "send a PDF to a JSP". That's where the confusion lies.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I know what you're asking for. Tell me if I'm close.

The user goes to page A.
One that page there is a link.
When that link is clicked, a PDF will be downloaded as an attachment (meaning that the user sees the 'Save-As/Open With' dialog).
The user saves the PDF to their machine.
You now want to show them a different page (page B) with some indication that the PDF was downloaded or links to go somewhere else.

Is that it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic