tomcat配置<mime-mapping> 實現自動匹配檔案類型html等

來源:互聯網
上載者:User

標籤:tomcat mime

Tomcat安裝完成之後預設可以開啟index.jsp檔案、但是如果你訪問index.html會顯示空白頁、原因是:在$tomcat/conf/web.xml設定檔裡、指定了什麼類型的檔案調用什麼程式開啟、但是預設沒有配置html或htm、所以我們要手動加上就可以了、以此類推、doc、war、ppt等都是一樣的方法。

[[email protected] ~]vim $tomcat/conf/web.xml

........................................................

 <mime-mapping>  

 <extension>htm</extension>   

 <mime-type>text/html;charset=gb2312</mime-type>   

 </mime-mapping>  

 <mime-mapping>  

 <extension>html</extension>   

 <mime-type>text/html;charset=gb2312</mime-type>   

 </mime-mapping>

........................................................

此段代碼可以加在任意位置、重啟後生效、:

650) this.width=650;" src="http://s5.51cto.com/wyfs02/M01/76/E4/wKiom1ZehtGwu-AuAAB_OaZiBsk645.png" title="1.png" alt="wKiom1ZehtGwu-AuAAB_OaZiBsk645.png" />


常用的檔案類型:

<mime-mapping>      <extension>doc</extension>      <mime-type>application/vnd.ms-word</mime-type>  </mime-mapping>  <mime-mapping>      <extension>gif</extension>      <mime-type>image/gif</mime-type>  </mime-mapping>  <mime-mapping>      <extension>htm</extension>      <mime-type>text/html</mime-type>  </mime-mapping>  <mime-mapping>      <extension>html</extension>      <mime-type>text/html</mime-type>  </mime-mapping>  <mime-mapping>      <extension>jnlp</extension>      <mime-type>application/x-java-jnlp-file</mime-type>  </mime-mapping>  <mime-mapping>      <extension>jpeg</extension>      <mime-type>image/jpeg</mime-type>  </mime-mapping>  <mime-mapping>      <extension>jpg</extension>      <mime-type>image/jpeg</mime-type>  </mime-mapping>  <mime-mapping>      <extension>js</extension>      <mime-type>application/x-javascript</mime-type>  </mime-mapping>  <mime-mapping>      <extension>pdf</extension>      <mime-type>application/pdf</mime-type>  </mime-mapping>  <mime-mapping>      <extension>png</extension>      <mime-type>image/png</mime-type>  </mime-mapping>  <mime-mapping>      <extension>rar</extension>      <mime-type>application/x-rar-compressed</mime-type>  </mime-mapping>  <mime-mapping>      <extension>txt</extension>      <mime-type>text/plain</mime-type>  </mime-mapping>  <mime-mapping>      <extension>xls</extension>      <mime-type>application/vnd.ms-excel</mime-type>  </mime-mapping>  <mime-mapping>      <extension>xml</extension>      <mime-type>text/xml</mime-type>  </mime-mapping>  <mime-mapping>      <extension>xul</extension>      <mime-type>application/vnd.mozilla.xul-xml</mime-type>  </mime-mapping>  <mime-mapping>      <extension>zhtml</extension>      <mime-type>text/html</mime-type>  </mime-mapping>  <mime-mapping>      <extension>zip</extension>      <mime-type>application/x-zip</mime-type>  </mime-mapping>  <mime-mapping>      <extension>zul</extension>      <mime-type>text/html</mime-type>  </mime-mapping>



其他常見的MIME類型:

超文字標記語言 (HTML)文本 .htm,.html text/html 

普通文本 .txt text/plain 

RTF文本 .rtf application/rtf 

GIF圖形 .gif image/gif 

JPEG圖形 .ipeg,.jpg image/jpeg 

au音效檔 .au audio/basic 

MIDI音樂檔案 mid,.midi audio/midi,audio/x-midi 

RealAudio音樂檔案 .ra, .ram audio/x-pn-realaudio 

MPEG檔案 .mpg,.mpeg video/mpeg 

AVI檔案 .avi video/x-msvideo 

GZIP檔案 .gz application/x-gzip 

TAR檔案 .tar application/x-


本文出自 “菜鳥的成長之路” 部落格,請務必保留此出處http://francis905.blog.51cto.com/3048056/1718824

tomcat配置<mime-mapping> 實現自動匹配檔案類型html等

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.