Sets the Content-Type header. Content-Type identifies the MIME type of the response document and the character set encoding.
To set the Content-Type header, use the following code:
response.setContentType("text/html; charset=gbk");
The default MIME type is text/plain. Some common MIME types include:
------------------------------------------------------------------
HTML format (.htm or .html): text/html
Adobe Portable Document (pdf): application/pdf
Microsoft Word (.doc): application/msword
Microsoft Excel (.xls): application/msexcel
Microsoft Powerpoint (.ppt): application/ms-powerpoint
Realaudio (.rm, .ram): audio/x-pn-realaudio
Text format (.txt): text/txt
Zipped files (.zip): application/zip
response.setContentType( "application/msword" );
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-type","application/pdf");
详请访问以下地址
本文详细解释了MIME类型及其在网页中的应用,包括常见MIME类型及其对应的文件扩展名,以及如何通过设置Content-Type头来指定响应文档的MIME类型和字符集编码。同时提供了实例代码演示如何在不同情况下正确设置Content-Type。
3183

被折叠的 条评论
为什么被折叠?



