title: JSF 2.0 Session Timeout throws IllegalStateException
body: <p>I have to logout the user after session timeout. I am using an <code>EventListenter</code> to clear out the session and also a <code>PhaseListener</code> to validate the user before doing any processiong.</p>
  
  <p>I am getting following exception when I try to click on any button after the session has timedout:</p>
  
  <pre><code>java.lang.IllegalStateException
  org.apache.catalina.connector.ResponseFacade.reset(ResponseFacade.java:310)
  com.sun.faces.context.ExternalContextImpl.responseReset(ExternalContextImpl.java:821)
  com.sun.faces.context.ExceptionHandlerImpl.throwIt(ExceptionHandlerImpl.java:251)
  com.sun.faces.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:141)
  com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
  com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:113)
  com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
  javax.faces.webapp.FacesServlet.service(FacesServlet.java:395)
  </code></pre>
  
  <p>My web.xml has following entries  :</p>
  
  <pre><code>&lt;error-page&gt;
      &lt;exception-type&gt;javax.faces.application.ViewExpiredException&lt;/exception-type&gt;
      &lt;location&gt;/content/country/default/jsp/login.faces&lt;/location&gt;
  &lt;/error-page&gt;
  &lt;error-page&gt;
      &lt;exception-type&gt;java.lang.Throwable&lt;/exception-type&gt;
      &lt;location&gt;/content/country/default/jsp/error.faces&lt;/location&gt;
  &lt;/error-page&gt;
  </code></pre>
  
  <p>The piece of code from the PhaseListener is </p>
  
  <pre><code>try{
      log.info("------------Check the method call-----------");
      if (log.isDebugEnabled())
          log.info("Authentication is needed.  Navigating to login page.");
      nh.handleNavigation(fc, null, NavigationConstants.LOGIN_FAILURE.toString());
      return;
  }catch(ViewExpiredException ve){
      log.info("Got the view expired exception. . . ");
      FacesContext.getCurrentInstance().getExternalContext().redirect("login.faces");
  }catch(IllegalStateException e){
      log.info("Got the IllegalStateException . . ");
      FacesContext.getCurrentInstance().getExternalContext().redirect("login.faces");
  }catch(Exception ex){
      log.info("Got the Exception . . ",ex);
      FacesContext.getCurrentInstance().getExternalContext().redirect("login.faces");
  </code></pre>