Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Make a file download

How to make a file to be downloaded rather than being opened while clicking on a link using JSP.
[96 byte] By [subhakar_nani] at [2007-11-11 7:55:12]
# 1 Re: Make a file download
That is a more of a browser issue than a server side/JSP issue. However, one thing you can do from the JSP side is to make sure the Content-type header matches the data you are sending. If you are sending a .zip file but the Content-type incorrectly says text/html, the browser will likely try to open it or display it.

This may not help at all for Internet Explorer, since MicroSoft ignores the RFC and checks the file extension, not the Content-type header.
Laszlo at 2007-11-11 22:37:01 >
# 2 Re: Make a file download
First Thank u very much,

Can u just give me sample code or even the path of the site that satiafies my query.

I mentioned JSP because i was developing the page dynamically using JSP.

Once again Thank u very much.
subhakar_nani at 2007-11-11 22:38:01 >
# 3 Re: Make a file download
JSP API - setHeader() method ( http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletResponse.html#setHeader(java.lang.String,%20java.lang.String))
Laszlo at 2007-11-11 22:39:05 >
# 4 Re: Make a file download
Once again thanks for the reply

Can u tell me how to download a html file from another html file by clicking on a link with a sample code.
subhakar_nani at 2007-11-11 22:39:59 >