Look at the stack trace who's calling the sendRedirect
at the wrong moment:
at javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:138)
at com.test.Bean.onErrorHome(Bean.java:262)
at com.test.Bean.<init>(Bean.java:51)
at com.test.service.BeanList.<init>(BeanList.java:84)
The page which you're redirecting to after logout is apparently referencing BeanList
in whose constructor another Bean
instance is manually been constructed in whose constructor onErrorHome()
method is been invoked which is calling HttpServletResponse#sendRedirect()
.
I'm not sure what you're all doing there, but given this problem it's definitely not done right. You're basically attempting to redirect while the page is busy generating HTML output. A part of that HTML has already been sent to the webbrowser (i.e. the response is already committed).
You've 2 options:
Move that logic to a servlet filter.
Perform the
onErrorHome()
job duringpreRenderView
event instead of in constructor.<f:event type="preRenderView" listener="#{beanList.init}" />
This method is invoked before JSF starts rendering/generating/sending HTML output, so you've all freedom to change the response to a different destination without risking
IllegalStateException: response already committed
errors.