title: Why is Java session attribute returning null
body: <p>Im trying to use the loggedIn String object as a flag. Why is it returning a null value when I print it out in a log?</p>
  
  <pre><code>@Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
  
      String loggedIn = "false"; //create a marker to tell if the user is logged in
  
      String url = "/index.jsp";
      HttpSession session = request.getSession();
  
      // get a user object from the session. 
      User sessionUser =(User) session.getAttribute("user");
  
      // create empty message strings
      String messageSuccess = "";
      String passwordMismatch = "";
  
  
      session.setAttribute("loggedIn", loggedIn);
      System.out.println("The loggedIn attribute of the session object is: " + session.getAttribute(loggedIn));
  
      String action = request.getParameter("action");
  
      if (action == null) {
          action = "join";
      }
  
      if (action.equals("join")) {
          url = "/new_customer.jsp";
  
      } else if (action.equals("signIn")) {
  
  //      User sessionUser = (User) session.getAttribute("sessionUser");
  
          if (sessionUser == null) {
  
              url = "/login_failure.jsp";
  
          } else {
  
              String username = request.getParameter("username");
              String password = request.getParameter("password");
  
              if (username.equals(sessionUser.getUserName()) &amp;&amp; password.equals(sessionUser.getPassword())) {
                  url = "/account_activity.jsp";
                  loggedIn = "true";
                  session.setAttribute("loggedIn", true);
  
              } else {
                  url = "/login_failure.jsp";
              }
          }
      }
  </code></pre>