I knew using setHeader we can achieve same funcionality as setContentType.
is same as
The doubt I got is while downloading an attachment in a particular format.
If i use response.setHeader("Content-disposition","attachment;filename=myFilePrint.xls");
The file is getting opened in an excel application. If this is so, then what is the use of content type? When the above setHeader automatically detects the extension of the file name given, if the extension is not provided it opens choose program window defined in my Operating System.
Firstly there are differences between browsers and how they detect file types using the content type and file name. Therefore providing both gives you the best chance that the response will behave as you expect. Omitting on or the other may have a different effect again.
Also, providing a file name is not the preferred mechanism for determining the content type (remember we're talking content type, not necessarily file type) even though IE may tell you otherwise.
Abdul Mujeeb Md
Joined: Aug 25, 2008
Thanks for your reply. I believe that I am clear with the doubt which i had.
Content type is for the browser to prepare itself to deal with the content it is about to receive. If you check the headers for a request sent by the browser, you can say that content-type of response corresponds to Accept header of request. Thus, there are default formats with which the browsers can deal without much effort from your side. However, for others, you need to take appropriate care.
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD