txt,xml等类型文件上传至Tomcat服务器后,浏览器点击下载链接是直接打开文件内容。需求是点击链接直接下载文件,通过配置Tomcat中conf目录下的web.xml来实现:
原配置
<mime-mapping>
<extension>xml</extension>
<mime-type>application/xml</mime-type>
</mime-mapping>
更改后
<mime-mapping>
<extension>xml</extension>
<mime-type>application/x-download</mime-type>
</mime-mapping>
txt类型也类似,将mime标签替换如下标签
<mime-type>application/x-download</mime-type>
然后重启Tomcat,亲测xml类型可以下载,txt类型未测,期待你的测试后回复我情况...