Cannot forward after response has been committed error after a sendRedirect
873078Jul 24 2012 — edited Jul 24 2012Hi,
I have been looking for on Google and other forums information about this error, but nothing solution works with my application.
In my JSF Tool, I effort an java.lang.NumberFormatException. When this error is catched, the flow goes to my SecurityFilter class and in the doFilter method I declare a sendRedirect method. But when this is executed I'm only obtain *"java.lang.IllegalStateException: Cannot forward after response has been committed"*
The error is launched when the application is trying lo load a table into a form.
The code is the next:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
HttpServletResponse resp = (HttpServletResponse) response;
try{
chain.doFilter( request, response );
}
catch(ServletException e){
resp.sendRedirect("/app/error/errorPage.jsf") ; // This line is the executed
return ;
}
catch(Exception e){
resp.sendRedirect("/app/error/errorPage.jsf") ;
}
}
If I write
FacesContext.getCurrentInstance().getExternalContext().redirect("/app/error/errorPage.jsf");
An NullPointerException is catched.
Some clue to solve? Thanks