Getting warning from JSF: The response was already committed by the time we tried to set the outgoing cookie for the flash

后端 未结 4 1920
夕颜
夕颜 2020-12-08 08:02

I have a page1.jsf, in this page i have a commandButton that put an object in ELFlash, and redirects to page2.jsf. In this page i recover the object by ELFlash. Everything w

4条回答
  •  感动是毒
    2020-12-08 08:44

    I think that problem might be related to http chunking. Solution is to increase response buffer size. After that cookies will be set correctly and Flash Scope should work too.

    Use this code:

    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() {}
    }
    

    And in web.xml:

    
        FlashScopeFixerFilter
        dk.sd.medarbejderdata.common.FlashScopeFixerFilter
    
    
        FlashScopeFixerFilter
        *.xhtml
    
    

提交回复
热议问题