To exit or invalidate the current session, you have the correct code, as shown below.
request.getSession().invalidate();
Now, when you click the back button of the browser, it will load the page from the cache. Therefore, to take care of this situation, you can do less than two things.
API HTML 5 History, "" .
, , - -.
/ , , .
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setHeader("Expires", "-1");
, .