码迷,mamicode.com
首页 > Web开发 > 详细

tomcat-5.0.28在https模式下无法下载文件问题解决

时间:2015-06-03 21:33:39      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:

tomcat-5.0.28https模式下无法下载文件问题解决


PS

 web.xml中的security-constraint写法:
  
tomcat-5.0.28中以http形式访问其web应用时【无法】自动跳转https
  
tomcat-5.5.20中以http形式访问其web应用时【可以自动跳转到https


 
环境
 tomcat-5.0.28(
配置https)jdk1.6
 
web
应用web.xml安全相关配置:
 <security-constraint>
  <web-resource-collection>
   <web-resource-name>OPENSSL</web-resource-name>
   <url-pattern>/*</url-pattern>
  </web-resource-collection>
  <user-data-constraint>
  <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  </user-data-constraint>
 </security-constraint>


问题:
 web
应用,在https模式下进行访问,IE8下无法下载页面中链接中指定的文件,但是在IE11中却无此问题
  jsp
页面中的文件链接形如:
   <a href="${cp }/xxxx/setup.exe">
下载xx</a>
  
问题解决:
 
书写一个文件下载Filter,并进行response.setHeader相关设置后,IE8在https模式下可以下载web应用中的文件
 
Filter
代码:
public class FileSSLFilter implements Filter {
 private static final Logger logger =Logger.getLogger("logger");
 
 public void init(FilterConfig filterConfig) throws ServletException {
  logger.info(">>>>>>>> FileSSLFilterinit.....");
 }


 public void doFilter(ServletRequest request,ServletResponse response,
   FilterChain chain) throws IOException, ServletException {
  HttpServletRequest httpServletRequest = (HttpServletRequest) request;
  HttpServletResponse httpServletResponse = (HttpServletResponse)response;
 
  //
通过https访问.xxx格式文件时
  if (httpServletRequest.getScheme() == "https"
    &&httpServletRequest.getRequestURI().endsWith(".exe"))
  {
   httpServletResponse.setHeader("Expires", "0");
   httpServletResponse.setHeader("Pragma","public");
   httpServletResponse.setHeader("Cache-Control", "must-revalidate,post-check=0, pre-check=0");
   httpServletResponse.setHeader("Cache-Control","public");
  }
 
  chain.doFilter(request, response);
 }


 public void destroy() {
  logger.info(">>>>>>>> FileSSLFilterdestroy...........");
 }
}


web.xml中增加:
 <filter>
  <filter-name>FileSSLFilter</filter-name>
 <filter-class>com.hispeed.model.filter.FileSSLFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>FileSSLFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>





tomcat-5.0.28在https模式下无法下载文件问题解决

标签:

原文地址:http://blog.csdn.net/jackpk/article/details/46351113

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!