response.setContentType 可以设置的值

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映射策略就是在网页中使用哪个应用程序(即插件),打开哪种文件。另外还有使用权限问题。比如对PDF文档,用“application/pdf “策略。这在动态网页中很常见。出现这种现象,有两种情形:一是使用一个应用程序去打开它不能打开的文档,比如用在标签中定义“DWG”文档用“application/pdf ”,就会出现无法打开的问题。二是文件扩展名符合要求,但文件内容(格式)不符合要求。你可以检查你浏览的网页源代码,获得出错信息。检查方法是:查看—源文件。寻找类似于“application/pdf “的字符串,就可以看到,要打开的文件是否与应用程序匹配。 追问 如果不相匹配 如何解决回答 这通常是由网页编写人来更改。比如:你在源文件里面找到你要打开的文件的HTML标签,在里面加上应用程序即可。比如,你要在网页上打开一个PDF文档,找到PDF文档那一行,在HTML标签里加上 type=“application/pdf “ 就可以了。比如以下HTML文件: <!----------测试MIME-----------><html> <head><title>测试MIME</title></head><body> <a type="application/pdf" href="test.pdf">测试MIME</a> </body> </html 将上面的代码保存为test.html,再在相同的位置存储一个pdf文档,双击它就会在网页中打开该文档。

详请访问以下地址

http://www.w3school.com.cn/media/media_mimeref.asp

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值