title: JSP Session.getAttribute() value return null
body: <p>I have no idea why my session.getAttribute("user") return not null but attribute value retun null after few minutes, it might due to session time out but why only the attribute value return null but other session still there even session.getAttribute("user") return not null.</p>
  
  <p>This is my web page flow, User Login</p>
  
  <p>LoginServlet </p>
  
  <pre><code>User s = new User();
  s.retriveuser();
  session.setAttribute("balance", s.getBalance());
  session.setAttribute("username", s.getUsername());
  session.setAttribute("user", s);
  </code></pre>
  
  <p>My Profile </p>
  
  <pre><code>        User user = new User();
          if (session.getAttribute("user") == null) {
              response.sendRedirect("login.jsp");
          } else {
              user = (model.User) session.getAttribute("user");
          }
  
   &lt;tr&gt;
           &lt;th&gt;Gender:&lt;/th&gt;
                &lt;td&gt;&lt;%=user.getGender()%&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;
           &lt;th&gt;Name:&lt;/th&gt;
           &lt;td&gt;&lt;%=user.getName()%&gt;&lt;/td&gt;
   &lt;/tr&gt;
  </code></pre>
  
  <p>It can display after the user login everything work fine, after few minutes the gender name ... will display null instead of redirect to login page. And my balance and username session still there.
  Before setting else user = (User) session.getAttribute("user"); I was using </p>
  
  <pre><code>&lt;jsp:useBean id="user" class="model.User" scope="session" /&gt;
  </code></pre>