欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java防止浏览器直接打开下载文件 浏览器JavaWebXML 

程序员文章站 2024-02-21 18:43:04
...

这个其实是在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>

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