title: Sessions in struts2 application
body: <p>I have created a web application in which I need to <strong>maintain the session</strong>
  if a user session is there, and then and only then will it allow the user to see the jsp.</p>
  
  <p>I have worked with jsp servlets before, but I'm new to struts2.</p>
  
  <p>Here I am <strong>setting username in my action class</strong>:</p>
  
  <p><strong>Revised Code</strong>    </p>
  
  <pre><code>private HttpSession session;
  
  public void setSession(HttpSession session) {
      // TODO Auto-generated method stub0
      this.session = session;
  }
  
  public HttpSession getSession() {
      return session;
  }
  
  public String getLoginStatus(){     
      session = request.getSession();
      session.setAttribute("userName", loginBean.getUsername());
      return SUCCESS;
  }
  </code></pre>
  
  <p>Now, when I am redirected to next page after an action, it shows the session value once. After that, on every page, I am finding null values in session.</p>
  
  <pre><code>&lt;%
      String userName = (String)session.getAttribute("userName");             
      System.out.println(userName);                        
  
      if(userName == null || userName.equals("") ){
          response.sendRedirect("login.jsp");
      }
  
  %&gt;
  </code></pre>
  
  <p>I read somewhere that the scope of an action class session is limited to one page - how could I solve this problem?</p>
  
  <p>Any example will be very helpful to me.</p>