Hi Matthias,
try this..
response.setHeader("Content-Disposition","filename=MyFile.exe");
Shane
----- Original Message -----
From: "Matthias Carlsson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, January 27, 2001 5:52 PM
Subject: Setting filename in response
: I've written a servlet which opens a file on the local harddrive and
: then sends the file's data back to the client. This works fine, but
the
: default filename the browser suggests is messed up and I'd like to
be
: able to set that. I've tried to set some headers in the
response-object
: like "filename" and "name", but it didn't work.
:
: Below is the code I use currently; may not be very efficient, but it
works.
:
: ====================================================
:
: UploadedFile file = cgResponse.getFile();
:
: ServletOutputStream out = response.getOutputStream();
: BufferedInputStream in = new BufferedInputStream(
: new FileInputStream(
: file.getFolder() + "/" + file.getName()
: ),
: 1024
: );
:
: response.setContentType(file.getContentType());
: response.setContentLength((int)file.getSize());
:
: int i;
: while ((i = in.read()) != -1) {
: out.write(i);
: }
:
: out.flush();
: out.close();
: in.close();
:
: ====================================================
:
: UploadedFile is a class which contains information about a
: specific file, like its location, content type, size etc.
:
: [ Matthias Carlsson ]
: [ Programmer (Java, XML/XSL, CGI/Perl, HTML/JS) ] [ Web Designer ]
: [ E-Mail : [EMAIL PROTECTED] ] [ ICQ: 1430647 ]
:
:
______________________________________________________________________
_____
: 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