title: Struts 2 Session in interceptor
body: <p>I am trying to access session object from within my interceptor by implementing <code>SessionAware</code> interface (I've implemented the <code>setSession</code> method), but I am not able to get my session object this way.</p>
  
  <p>Then I tried <code>ActionContext.getContext().getSession()</code> and I am able to get the session, but I don't know but its coming out to be empty for only the first time in every browser for every user &amp; then it comes filled when another action is invoked. </p>
  
  <p>I assume there is something wrong going with the session. Why is it giving me an empty session only for the first time? Does it set something only after giving empty session for the first time?</p>
  
  <p>If this is the case then everyone will be shown as guest on their first request &amp; then with a username on their 2nd request &amp; hence forth.</p>
  
  <p>Or am I getting the session in the wrong way?</p>
  
  <p>I saw code to get sessions in interceptors, but this does not work for me as it cannot find the constant <code>HTTP_REQUEST</code>. </p>
  
  <pre><code>final ActionContext context = invocation.getInvocationContext();
  
  HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
  
  HttpSession session = request.getSession(true);
  
  Object user = session.getAttribute(Constants.USER_HANDLE);
  </code></pre>
  
  <p>Any suggestion on resolving any of the problems?</p>
  
  <p>Something I forgot to mention - my website is a secure site(https), so if the user is not logged in, it would not let him enter the website &amp; if he is logged in, at least his username should be there in the session. Shouldn't it be?</p>