I have a servlet which is connecting to a url.i want to display the contents of this url which is a pdf file
in the browser.How do I achieve this in the servlet?
I was thinking if I could write to a sample pdf file placed at a location the response from the servlet and then show that file in the browser.Is there any direct way to display the pdf directly from the servlet in the browser.
B elow the servlet code I am using. I am sure i am missing something.I am geting the response back but nothing is written to the test.pdf file.How can I use the response I am geting back from the url to show as a pdf file?

885522 wrote:
I was thinking if I could write to a sample pdf file placed at a location the response from the servlet and then show that file in the browser.

No, don't do that.

Is there any direct way to display the pdf directly from the servlet in the browser.

Yes, simply copy the response from that URL to your servlet's response output stream. No need to muck about with temporary files. Don't forget to set the response headers correctly (before you send the response data).

repInStream.close();
out.close();
} catch (Exception ex) {
System.out.println("the exception in servlet is" + ex);
}
}
The pdf still doesnt opens up in the browser.Is this code sufficient to open the pdf or I have to write some other code
where I am calling the servlet as in my post to show the pdf.I am having an applet and from the applet I am forming a url to servlet and this servlet should open up a pdf so any other changes required to make it work or something wrong with this code.
Please help.Your comments have helped me reach till here.

Don't you think that flushing a stream AFTER you close it is kind of odd or to be more precise: WRONG? Not that it matters, closing a stream will flush it first. But this kind of thing just proves that you are copy/pasting code from places without really understanding what it does. That just won't work.
In stead of trying to do this in the servlet, why don't you try to create a little java program that simple copies a file from A to B? If you can get that to work properly, the same code should be used to do your servlet. Much easier to test that way.

Thanks for the reply.I am new to working with streams .
May be I am wrong.Actually copying from location A to B will not work for me.
The url i am hitting generates a random report (adhoc) on the fly and is not saved anywhere .
The url is of a report server so I have to show the reports on the fly.

My only concern is how to show this pdf file to the browser.If I type the url I am trying to hit in my browser ,the reports
opens up as a pdf but not with Java code.