"Jo�o Carlos Costa" wrote:

> I want to be able to allow users to download ANY binary file from a
> web server using servlets. The servlet must operate on either NN and
> IE environments.
> I have tried the following:
>
> res.setContentType("application/x-zip-compressed; name=\"" + itemName+
> '\"');
> res.setHeader("Content-disposition", "attachment; filename=\\"" +
> itemName +'\"\);
> res.setContentLength(getItem().length);
>
> This works fine, if I want to download a zip file. But if I want to
> download a file which is not a zip, how am I supposed to do? I
> developed a servlet (works beautifully), different from Jason
> Hunter's, that uploads ANY binary file using multipart/form-data and I
> simply can't do the same for a download.
>
> Does any of you, Servlet experts, have an example of a servlet that
> downloads ANY binary file? I would appreciate any help from you.
>
> Thanks
> ===
> Joao Carlos Costa
>

The browser listens for the content type of the file you are downloading in
order to decide what to do with it.  You can determine the content type to
send by calling

    getServletContext().getMimeType(itemName);    // itemName is the filename
of the file to be downloaded

and use this to replace the "application/x-zip-compressed" string constant.

Craig McClanahan

___________________________________________________________________________
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