java教程

最简单的Java防止浏览器直接打开下载的文件(弹出另存为对话框)

位置:首页 > java教程 > 安装配置,2013-04-30
这个其实是在web.xml文件中配置mime下载文件类型就可以了,配置的示例:  <mime-mapping>  <extension>doc</extension>...

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

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

TAGS:Java防止浏览器直接打开下载文件Java弹出另存为对话框Java文件下载

猜你喜欢

NewHot