java防止浏览器直接打开下载的文件

 这个其实是在web.xml文件中配置mime下载文件类型就可以了,配置的示例:

<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> 


这样就可以防止在浏览器是直接打开文件,而是弹出下载框供用户下载了。

阅读更多
文章标签: 浏览器 java
上一篇Oracle job + 存储过程学习笔记
下一篇Java 下载文件不在浏览器中直接打开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭