Ok,thanks a lot!

Anyway  I have two other questions please:

1)If the file format is readable from some application installed on the
client machine
(for example Acrobat Reader can read .pdf files) will be the file opened
automatically from the user's Web browser when it arrives?

2)Before sending the file to the user (as indicated in your piece of code)
I must download it from my servlet. How can I do it? Can you give me an
example please?
When I download the file how can I send it "on the fly" to the user without
saving it on disk before?

Thanks a lot for your help!

                     Luca



-----Messaggio originale-----
Da: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]Per conto di steve
martin
Inviato: martedi 10 settembre 2002 11.56
A: [EMAIL PROTECTED]
Oggetto: Re: How can I downlod a (pdf) file using a servlet?


>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

___________________________________________________________________________
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