In my JSF application I need to redirect from the the managed bean constructor. I have following code to do so:
HttpServletResponse httpServletResponse = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
httpServletResponse.sendRedirect("HomeV.jsf");
but this is throwing following exception:
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)
at javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:126)
at com.sun.faces.context.ExternalContextImpl.redirect(ExternalContextImpl.java:419)
I even tried following:
FacesContext.getCurrentInstance().getExternalContext().redirect("HomeV.jsf");
as mentioned in the stackoverflow question related to this here but still I face the same exception.