-1

I am developing a web application using struts2 and jsp. I want to implement logout functionality in it. Although, I am able to remove the session but the browser's back button sends me back to the previously visited pages. I added the following code in each of the jsp file for preventing the caching. But this is not working. Kindly help.. So that after logout one cannot access the pages. Code :-

<%
response.setHeader("Cache-Control","no-cache"); // HTTP 1.1 
response.setHeader("Pragma","no-cache"); //HTTP 1.0 
response.setDateHeader ("Expires", 0); 
%>

I have added this code in head tag of each and every jsp page.
  • 1
    Check [Making sure a web page is not cached, across all browsers](https://stackoverflow.com/questions/49547) and [Refresh a jsp page on browser back button click](https://stackoverflow.com/questions/22159556). – f_puras Jun 27 '16 at 13:39

1 Answers1

0

You could use JavaScript into your jsp page and use some logic with JSTL to run this script only when it is a logout action.

history.pushState(null, null, '');
        window.addEventListener('popstate', function (event) {
            history.pushState(null, null, '');
        });

It prevents user to back to previous page.

Andrew Ribeiro
  • 576
  • 1
  • 5
  • 17