Try,
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;
filename=\"fname.txt\"");
Where fname.txt is the name of the file you want to be shown on the file save
as.
Mano
-----Original Message-----
From: Matthias Carlsson [mailto:[EMAIL PROTECTED]]
Sent: Saturday, January 27, 2001 11:23 PM
To: [EMAIL PROTECTED]
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