Cannot create a session after the response has been committed

后端 未结 4 1836
余生分开走
余生分开走 2020-12-30 02:40

Opening the JSF page gives me the following exception:

Caused by: java.lang.IllegalStateException: Cannot create a session after the response has been

相关标签:
4条回答
  • 2020-12-30 03:24

    It was happening to me too.

    I used to have Mojarra 2.1.13 and after updating it to 2.1.29 the problem solved itself, without any changes in my code.

    0 讨论(0)
  • 2020-12-30 03:25

    The reason is that:

    1. JSF stores the page component structure in HttpSession
    2. If the page content is very large and the session has not been previously created, some response may have been written and the error above happens

    So the solution is to create the session before the Facelet (/JSP) page is printed. An crude example could be like:

    @PostConstruct
    void initialiseSession() {
        FacesContext.getCurrentInstance().getExternalContext().getSession(true);
    }
    

    /napu

    0 讨论(0)
  • 2020-12-30 03:36

    I put this in my web.xml to solve the problem for one of my apps.

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    

    What is weird though is that I have several other applications hosted on this same glass fish instance that doesn't require this voodoo in the web.xml.

    I strongly want to believe this is not the solution, cos it doesn't make any sense to me why this particular app requires it and the others didn't. But for now it works.

    0 讨论(0)
  • 2020-12-30 03:46

    [SOLVED]

    It took days to diagnose this problem, but finally I am able to solve this problem.

    It was actually @ViewScoped and it has a managed property DAO object which was not serialized. So after view is rendered, facelets also produce this exception, but JSF view already rendered and that's why this exception showed.

    Solution: Make all objects serialized in @ViewScoped bean, and mark "transient" who are not serialized like in my case it was DAO object in JSF @ViewScoped.

    0 讨论(0)
提交回复
热议问题