I'm trying to name a file that is being downloaded via a servlet. I have done
this:

 response.setContentType(mimeType); // i.e. "application/x-zip-compressed"
response.setHeader("Content-dispostion", "attachment; filename=\"" + itemName +
"\"");
response.setContentLength(getItem().length) ;
.. then I print it

The file downloads fine, works and everything, but the filename is incorrect (it
is still the name of the servlet, although it does append the suffix of the
filename, i.e. "ServletName.zip").

Any ideas?



Roger Niederland wrote:

> Try this:
> ------------
> res.setContentType("application/octet-stream") ;
> res.setHeader("Content-dispostion", "attachment;filename=" + myfilename ) ;
> res.setContentLength(length) ;
>
> <read file and output the stream of data for browser>
> -------------
>
> -----Original Message-----
> From: Knut Martin Tornes <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
> Date: Friday, January 01, 1999 12:29 PM
> Subject: Naming files in Download servlet
>
> >Hi folks!
> >
> >I currently have a servlet used to download files from an internal
> >network disk (outside the web server's path). To do this, the servlet
> >opens the file and streams the file as binary data. My problem is to
> >give the stream a name other than the servlet's name. I've tried to set
> >various HTTP header info but without any luck so far.
> >
> >To clarify a little bit:  the URL
> >http://my.domain.com:8080/servlet/Download?some_parameter=some_value
> >make Internet Explorer and Netscape (and probably other browsers as
> >well) suggest 'Download.' as the name of the file to download.
> >
> >Any suggestions?
> >
> >thanx in advance,
> >Knut Martin Tornes,
> >objectBOX
> >Norway
> >
> >===========================================================================
> >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

___________________________________________________________________________
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