>From chapter 12 of "Java for the Web with Servlets,
JSP and EJB" by Budi Kurniawan (New Riders), you need
to set the HTTP header:

<%
// do some verification here

if (verified) {
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment;
filename=\"" + filename + "\"");

java.io.FileInputStream fileInputStream = new
java.io.FileInputStream(filepath + filename);
int i;
while ((i=fileInputStream.read()) != -1) {

  out.write(i);
}
fileInputStream.close();
out.close();

} //end if
%>


sm.

--- "Raghupathy, Gurumoorthy"
<[EMAIL PROTECTED]> wrote:
> Look at HTTPUrlConnection ( if using http ) or
> HttpsURLConnection. ( JSSE )
> ...
> get the file .. and then set the contenttype ( and
> send it back to the
> client on the fly ).....
>
> Regards
> Guru
>
>
> -----Original Message-----
> From: Luca Ventura [mailto:[EMAIL PROTECTED]]
> Sent: 10 September 2002 10:18
> To: [EMAIL PROTECTED]
> Subject: How can I downlod a (pdf) file using a
> servlet?
>
>
> Hello everybody!
>
> I have problem: I have a web-site where there is a
> servlet running....let's
> suppose the servlet name is "MyServlet". Some users
> can connect to the
> web-site
> and request to the servlet to download a .pdf file
> (but the file type is not
> important and could be different). The file name is
> passed to the servlet
> sending a parameter, for example connecting
> to the url:
>
> http://mydomain.com//MyServlet?FileName=File.pdf
>
>
> Note that the requested file is on a different
> web-site (let's suppose
> http://otherdomain.com)
> and the servlet must connect to this other site and
> download the file
> requested ("File.pdf") before sending it back to the
> user.
>
> That I need to know is:
>
> 1)How can I download a file from another site using
> a servlet? I
> mean....Which java code must
>    I add to my servlet to do this?
>
> 2)Before sending the file to the user who requested
> it must I save it on
> disk or can I send
> it to the user "on the fly"?
>
> 3)How can I send the file from the servlet to the
> user that requested it?
>
> I hope someone can help me!
>
> Thanks a lot in advance.
>
>                                         Luca
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED]
> and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives:
>
http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
>
http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help:
> http://www.lsoft.com/manuals/user/user.html
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED]
> and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives:
>
http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
>
http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help:
> http://www.lsoft.com/manuals/user/user.html
>


__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to