web.xml中的mime-type标签作用与使用

时间:2021-08-12 21:23:00

MIME类型就是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器会自动使用指定应用程序来打开。多用于指定一些客户端自定义的文件名,以及一些媒体文件打开方式。 每个MIME类型由两部分组成,前面是数据的大类别,例如声音audio、图象image等,后面定义具体的种类

<mime-mapping> <extension>doc</extension> <mime-type>application/msword</mime-type> </mime-mapping>

<mime-mapping> <extension>xls</extension> <mime-type>application/msexcel</mime-type> </mime-mapping>

<mime-mapping> <extension>pdf</extension> <mime-type>application/pdf</mime-type> </mime-mapping>

<mime-mapping> <extension>zip</extension> <mime-type>application/zip</mime-type> </mime-mapping>

<mime-mapping> <extension>rar</extension> <mime-type>application/rar</mime-type> </mime-mapping>

<mime-mapping> <extension>txt</extension> <mime-type>application/txt</mime-type> </mime-mapping>

<mime-mapping> <extension>chm</extension> <mime-type>application/mshelp</mime-type> </mime-mapping>

<mime-mapping> <extension>mp3</extension> <mime-type>audio/x-mpeg</mime-type> </mime-mapping>

常见的MIME类型
超文本标记语言文本 .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-tar

对html静态页面设置编码
<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>