title: How to keep alive a session attribute
body: <p>I have a "look up" html page that works together with a java HttpServlet class that handles some functionality and sends the results to a jsp page. </p>
  
  <p>To perform the look up I need a loginresult object that I put in the session in a different servlet. </p>
  
  <p>This is what happens in the login servlet:</p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          response.setContentType("text/html");
          PrintWriter out = response.getWriter();
          // get attributes that were filled in on the login webpage
          request.getAttribute("username");
          request.getAttribute("password");
          String username = request.getParameter("username");
          String password = request.getParameter("password");
          LoginManager loginManager = new LoginManager(username.trim(), password.trim());
          if (loginManager.doLogin() == true) {
              javax.servlet.http.HttpSession session = request.getSession();
              session.setAttribute("loginResult", loginManager.getLoginResult());
              session.setAttribute("binding", loginManager.getBinding());
              response.sendRedirect("lookup.html");
  </code></pre>
  
  <p>This is what happens on the look up servlet</p>
  
  <pre><code>request.setCharacterEncoding("UTF-8");
              response.setContentType("text/html");
              javax.servlet.http.HttpSession session = request.getSession();
              LoginResult lr = (LoginResult) session.getAttribute("loginResult");
              if(lr == null)
              {
                  throw new Exception("Your session has expired, please log in again");
              }
  
              // some look up code
  
              RequestDispatcher dispatcher = request.getRequestDispatcher("result.jsp");
              request.setAttribute("result", result);
              request.setAttribute("question", question);
              request.setAttribute("xml", xml);
              dispatcher.forward(request, response);
  </code></pre>
  
  <p>In my jsp page is a input button that does the following : ONCLICK="window.location.href='lookup.html'"/></p>
  
  <p>Sometimes when i leave my result page unfocused or minimize or whatever or I wait too long and I click the return to the look up page it appears that my loginresult object == null. 
  So in my opinion it seams to be expired. Although I thought that the Apache Tomcat server keeps sessions alive for 30 minutes standard.</p>
  
  <p>Any guess why my session attribute disappear?</p>