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?
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).
Joined: Apr 30, 2010
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.
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 .
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.