Cannot create a session after the response has been committed

别等时光非礼了梦想. 提交于 2019-11-30 06:48:40

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

Faisal Basra

[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.

Aardvocate Akintayo Olusegun

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.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!