title: How to redirect to login page if session is expired?
body: <pre><code>    HttpSession session = request.getSession();
      User user = (User)session.getAttribute("user");
      if(user == null){
          response.sendRedirect("login.jsp");
      }
      System.out.println(user);
  </code></pre>
  
  <p>I am writing this code in a servlet and deploying it in Tomcat Server. After the session expires, session is automatically created but the "user" attribute becomes null. But the page is not redirected to "login.jsp" and "null" gets printed on the console.</p>
  
  <p>I am using MyEclipse IDE.</p>