A.com的页面,使用iframe包含B.com的页面,后者写入的cookie,IE会忽略,
导致后者的系统,无法使用cookie,间接导致Session无法使用~~
解决办法,使用P3p Header,IE就会接收Cookie了~~
搜了半天,tomcat貌似无法通过配置实现自定义Header,
只能在web app中增加Filter来实现了。
package cn.xxx.yyy;
import java.io.IOException;
import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletResponse;
public class HeaderFilter implements Filter {
@Override public void destroy() { }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// iframe引起的内部cookie丢失 HttpServletResponse res = (HttpServletResponse) response; res.setHeader("P3P", "CP=CAO PSA OUR"); if (chain != null) { chain.doFilter(request, response); } }
@Override public void init(FilterConfig arg0) throws ServletException {
}
}
然后在web.xml中增加
<!-- ======================写P3P Header,解决IE的iframe的cookie问题======================= --> <filter> <filter-name>P3pHeaderFilter</filter-name> <filter-class>cn.xxx.yyy.HeaderFilter</filter-class> </filter> <filter-mapping> <filter-name>P3pHeaderFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
即可。
我是把它放在了设置字符编码的filter后面,比较靠前吧。
|