title: Struts 2 session invalidation with setting request session to a new session
body: <p>In my Struts application once an user login I need to invalidate the current session and create a new session. I invalidate the session with</p>
  
  <pre><code>getHttpServletRequest().getSession().invalidate();
  </code></pre>
  
  <p>And I create a new session as </p>
  
  <pre><code>getHttpServletRequest().getSession(true);
  </code></pre>
  
  <p>The problem here is after above I try to access <code>getSession()</code> it gives the state invalid exception; <code>HttpSession</code> is invalid.</p>
  
  <p><code>getSession()</code> returns a map where in my action class I implements <code>SessionAware</code> which has the <code>setSession(Map session)</code>.</p>
  
  <p><strong>EDIT: Below is the exception</strong></p>
  
  <pre><code>Error creating HttpSession due response is commited to client. You can use the CreateSessionInterceptor or create the HttpSession from your action before the result is rendered to the client: HttpSession is invalid
  java.lang.IllegalStateException: HttpSession is invalid
  </code></pre>
  
  <p>So, what I assume the problem is the Struts <code>getSession()</code> still reference the session which I've invalidated. </p>
  
  <p>How to make the Struts <code>getSession()</code> to reference the new session which I've created?</p>