让下载的文件不要打开……

temp1898 发布于 2011/03/31 17:08
阅读 357
收藏 1

要下载的东西总是在浏览器中打开,不知怎样搞,在web.xml已经设了,不起作用,请帮忙看一下。

网上搜到的答案,对了,如果我想要下载的所有文件都不要在浏览器中打开,怎样设置。先谢了……

web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
 </filter>
 <filter>
  <filter-name>struts-cleanup</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
 </filter>
 <filter>
  <filter-name>CharSetFilter</filter-name>
  <filter-class>servlet.filter.CharSetFilter</filter-class>
 </filter>
 <filter>
  <filter-name>LoginFilter</filter-name>
  <filter-class>servlet.filter.LoginFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>struts-cleanup</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>CharSetFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>LoginFilter</filter-name>
  <url-pattern>/work/*</url-pattern>
 </filter-mapping>
 <servlet>
  <servlet-name>Login_Check</servlet-name>
  <servlet-class>servlet.login.Login_Check</servlet-class>
 </servlet>
 <servlet>
  <description>Jsbq operation</description>
  <display-name>Qk_fire</display-name>
  <servlet-name>Jsbq_Op</servlet-name>
  <servlet-class>servlet.jsbq.Jsbq_Op</servlet-class>
 </servlet>
 <servlet-mapping>
  <servlet-name>Login_Check</servlet-name>
  <url-pattern>/Login_Check</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
  <servlet-name>Jsbq_Op</servlet-name>
  <url-pattern>/Jsbq_Op</url-pattern>
 </servlet-mapping>
 <session-config>
  <session-timeout>60</session-timeout>
 </session-config>
 <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>ppt</extension>
  <mime-type>application/vnd.ms-powerpoint</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>mht</extension>
  <mime-type>text/x-mht</mime-type>
 </mime-mapping>
 <mime-mapping>
  <extension>iso</extension>
  <mime-type>application/octet-stream</mime-type>
 </mime-mapping>
 <mime-mapping>
  <extension>ape</extension>
  <mime-type>application/octet-stream</mime-type>
 </mime-mapping>
 <mime-mapping>
  <extension>rmvb</extension>
  <mime-type>application/octet-stream</mime-type>
 </mime-mapping>
 <mime-mapping>
  <extension>ico</extension>
  <mime-type>image/x-icon</mime-type>
 </mime-mapping>
 <mime-mapping>
  <extension>jpg</extension>
  <mime-type>image/jpeg</mime-type>
 </mime-mapping>
 <mime-mapping>
  <extension>gif</extension>
  <mime-type>image/gif</mime-type>
 </mime-mapping>
 <mime-mapping>
  <extension>bmp</extension>
  <mime-type>image/bmp</mime-type>
 </mime-mapping>
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
 <login-config>
  <auth-method>BASIC</auth-method>
 </login-config>
</web-app>

加载中
0
cnblogs
cnblogs

把所有文件类型都设置为 application/octet-stream 这样就不会在浏览器打开了。

0
一号男嘉宾
一号男嘉宾

楼上的头像看了让人蛋疼~

0
temp1898
temp1898

谢谢,我试一下……

0
temp1898
temp1898

还是不行,可能是怪我设置的方式不对,我是直接把要下载的东西搞成了URL链接^_^(二楼的头像有点像吴孟达^_^)

0
华宰
华宰

引用来自#5楼“temp1898”的帖子

还是不行,可能是怪我设置的方式不对,我是直接把要下载的东西搞成了URL链接^_^(二楼的头像有点像吴孟达^_^)

如果不行,那应该是设置没起效,肯定行的

0
temp1898
temp1898

嗯,测试中……

返回顶部
顶部