wood burning stoves 2.0*
The moose likes Servlets and the fly likes Display a pdf in another jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Display a pdf in another jsp" Watch "Display a pdf in another jsp" New topic
Author

Display a pdf in another jsp

fer ribeirao
Greenhorn

Joined: Apr 30, 2010
Posts: 5
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

Joined: Jan 10, 2002
Posts: 61095
    
  66

Ajax is not an appropriate technology for this. You want to return thee PDF response to the browser, not your script.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
fer ribeirao
Greenhorn

Joined: Apr 30, 2010
Posts: 5
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

Joined: Dec 22, 2008
Posts: 16

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

Joined: Apr 30, 2010
Posts: 5
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

Joined: Jan 10, 2002
Posts: 61095
    
  66

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

Joined: Apr 30, 2010
Posts: 5
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

Joined: Jan 10, 2002
Posts: 61095
    
  66

That doesn't shed any light on what you are trying to accomplish.
Anthony Accioly
Greenhorn

Joined: Dec 22, 2008
Posts: 16

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

Joined: Jan 10, 2002
Posts: 61095
    
  66

It's hard to tell because what the original poster wants to do is not being clearly explained.
Anthony Accioly
Greenhorn

Joined: Dec 22, 2008
Posts: 16

Out of Topic: I keep hitting the Submit Button thinking I'm hitting "Preview" lol
fer ribeirao
Greenhorn

Joined: Apr 30, 2010
Posts: 5
Excuse me if I did not understand, but it would be easier if I could explain in Portuguese!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

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

Joined: Dec 11, 2004
Posts: 13410

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?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display a pdf in another jsp