有时候下载某种文件的时候会变成浏览器直接打开,而不是我们所要的下载。
在tomcat5.x下conf/web.xml进行如下配置可解决
<mime-mapping>
<extension>csv</extension>
<mime-type>application/csv</mime-type>
</mime-mapping>
以下为转载
解决在Resin、Tomcat下,下载csv文件时直接用IE打开问题
<mime-mapping>
<extension>csv</extension>
<mime-type>application/oct-stream</mime-type>
</mime-mapping>
解决方法如下:
Resin:
打开Resin目录下的conf/app-default.xml,在相应的位置加入
<web-app-default>
......
<mime-mapping extension=".xsl" mime-type="text/xml"/>
<mime-mapping extension=".xwd" mime-type="image/x-xwindowdump"/>
<mime-mapping extension=".csv" mime-type="application/oct-stream"/>
<mime-mapping extension=".zip" mime-type="application/zip"/>
<mime-mapping extension=".z" mime-type="application/octet-stream"/>
<resin:import path="WEB-INF/web.xml" optional="true"/>
<resin:import path="WEB-INF/resin-web.xml" optional="true"/>
</web-app-default>
Tomcat:
打开Tomcat目录下的conf/web.xml,在相应的位置加入
<mime-mapping extension=".csv" mime-type="application/oct-stream"/>
=============================================================================================
解决在Resin、Tomcat下,下载rar文件时直接用IE打开问题
原因是因为Resin、Tomcat服务器配置中没有设置相关的mime与RAR文件对应。
解决方法如下:
Resin:
打开Resin目录下的conf/app-default.xml,在相应的位置加入
<mime-mapping extension=".rar" mime-type="application/rar"/>
保存,重启Resin,清空IE临时文件即可(切记)!
Tomcat:
打开Tomcat目录下的conf/web.xml,在相应的位置加入
<mime-mapping>
<extension>rar</extension>
<mime-type>application/rar</mime-type>
</mime-mapping>
保存,重启Tomcat,清空IE临时文件即可(切记)!
注:下载别类型的文件也一样,如txt文件,把相应的rar改成txt即可
=============================================================================================
web mime-mapping 作用
作用是用于规定下载格式
<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