title: Clear history onclick of browser's back button
body: <p>I am working on one project which has lot pf pages..</p>
  
  <p>My pages structure is as follows:
  login >> dashboard >> add >> view >> edit and so on...
  Problem I am facing is :
  If I clicked back button and I am on login page then again If I have clicked back button it is redirecting to dashboard page again.</p>
  
  <p>What I want is:
  I want to clear browsers history or it should not go to dashboard page from login page if I pressed back button from login page.</p>
  
  <p>I tried lot of code snippets,all code I have added in login page:
  Some of them are below:</p>
  
  <p>Javascript code:
  1)</p>
  
  <pre><code>var Backlen=history.length;   
  history.go(-Backlen);   
  window.location.href=contextPath + "login.jsp";
  </code></pre>
  
  <p>2)</p>
  
  <pre><code>function preventBack(){window.history.forward();}
  setTimeout(preventBack(), 0);
  window.onunload=function(){null};
  </code></pre>
  
  <p>3) </p>
  
  <pre><code>function disableBack() { window.history.forward() }
  window.onload = disableBack();
  window.onpageshow = function(evt) { if (evt.persisted) disableBack() }
  </code></pre>
  
  <p>Also tried Java code as well- cleared sessions using below code:</p>
  
  <pre><code>&lt;%  
  String forwardUrl = "";
  if(sessionTimeout!=null)
  {
  request.setAttribute("timeoutMessage", sessionTimeout);
  forwardUrl="login.jsp?locale="+locale+"&amp;timeoutMessage="+sessionTimeout;
  }else
  {
  forwardUrl="login.jsp?locale="+locale;  
  request.getSession().removeAttribute(sessionTimeout); 
  }
  %&gt; 
  </code></pre>