response.setContentType 可以設定的值

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.