I create a servlet in Tomcat that pass a file to the client, like this:
// Open the file and output streams
FileInputStream in = new FileInputStream(file);
OutputStream out = response.getOutputStream();
// Copy the contents of the file to the output stream
byte[] buf = new byte[1024];
int count = 0;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
}
in.close();
out.close();
}
When the client download the file and save it, the name of the file is
the name of the servlet.
The big question is: how can I show a name that I want instead of the
name of the servlet?
Thank you
Alb
Oliver Wong - 13 Jun 2006 15:14 GMT
>I create a servlet in Tomcat that pass a file to the client, like this:
>
[quoted text clipped - 16 lines]
> The big question is: how can I show a name that I want instead of the
> name of the servlet?
Send the following HTTP headers:
Content-Disposition: attachment; filename="downloaded.pdf"
- Oliver
Andrea Desole - 13 Jun 2006 15:17 GMT
> I create a servlet in Tomcat that pass a file to the client, like this:
>
[quoted text clipped - 16 lines]
> The big question is: how can I show a name that I want instead of the
> name of the servlet?
use the Content-Disposition header:
http://www.onjava.com/pub/a/onjava/excerpt/jebp_3/index3.html