我认为这个问题可能与http分块有关。解决方案是增加响应缓冲区大小。之后,cookie 将被正确设置,Flash Scope 也应该可以工作。
使用此代码:
public class FlashScopeFixerFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// Below line: response.getWriter() must be invoked to buffer size setting work. Just DO NOT touch this!
response.getWriter();
HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper((HttpServletResponse) response);
wrapper.setBufferSize(10000000);
chain.doFilter(request, wrapper);
}
@Override
public void init(FilterConfig arg0) throws ServletException {}
@Override
public void destroy() {}
}
在 web.xml 中:
<filter>
<filter-name>FlashScopeFixerFilter</filter-name>
<filter-class>dk.sd.medarbejderdata.common.FlashScopeFixerFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>FlashScopeFixerFilter</filter-name>
<url-pattern>*.xhtml</url-pattern>
</filter-mapping>