标签:
tomcat-5.0.28在https模式下无法下载文件问题解决
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