title: How to create session for login and logout in java
body: <p>This is the code that I have written in login page</p>
  
  <pre><code>HttpSession session = request.getSession(true);
  session.setAttribute("name", user1);        
  String nme=(String) session.getAttribute("name");
  </code></pre>
  
  <p>And, This is the  code for <strong>logout.jsp</strong></p>
  
  <pre><code>&lt;% request.getSession().invalidate();
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>if(session!=null){
     session=null;
  }
  </code></pre>
  
  <p>OR</p>
  
  <pre><code> request.getSession().setAttribute("name", null); //it just assigns null to attribute
  
   response.sendRedirect("login.jsp");
   %&gt;
  </code></pre>
  
  <p>session is creating, But after logout button is working....
  I want that back button should not work.</p>