Cannot create a session after the response has been committed

后端 未结 4 1881
余生分开走
余生分开走 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: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

提交回复
热议问题