Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Working with sessions (Login and Logout)

 
Angelo Tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I currently have a small program that goes like this:

User logs in: (login.jsp)


User is redirected to index page: (index.jsp)


User clicks on log-out button: (logout.jsp)



what i want to achieve here is that whenever the user logs-out,
pressing the back button on the browser shouldn't work,
meaning the user should be redirected back to the login page when the back button is pressed.
But for some reason clicking back still redirects the user to the index page.
I actually have to refresh the index page just so redirecting to it wouldn't work.

The session does get removed, its just that i want to get rid of the "back" issue.

p.s. aside from session.setAttribute("username", null);
i have also tried session.invalidate(); and session.removeAttribute("username");
although those didn't seem to have helped.
 
Stefan Evans
Bartender
Posts: 1780
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pushing the back button will serve the page from the browsers cache.
No request is made to the server to display this page, the browser just loads up exactly what it was sent before.

If you want to stop it doing this, then you have to put "don't cache me" tags on your JSP pages, so that it has to go to the server each time.
The FAQ on this site has a page explicitly about using NoCacheHeaders

cheers,
evnafets
 
Angelo Tan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:Pushing the back button will serve the page from the browsers cache.
No request is made to the server to display this page, the browser just loads up exactly what it was sent before.

If you want to stop it doing this, then you have to put "don't cache me" tags on your JSP pages, so that it has to go to the server each time.
The FAQ on this site has a page explicitly about using NoCacheHeaders

cheers,
evnafets


got it.

thanks a bunch!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic