aspose file tools*
The moose likes JSP and the fly likes Working with sessions (Login and Logout) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Working with sessions (Login and Logout)" Watch "Working with sessions (Login and Logout)" New topic
Author

Working with sessions (Login and Logout)

Angelo Tan
Greenhorn

Joined: Oct 29, 2010
Posts: 10
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

Joined: Jul 06, 2005
Posts: 1016
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

Joined: Oct 29, 2010
Posts: 10
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.
 
subject: Working with sessions (Login and Logout)
 
Similar Threads
problem without logout, how to solve it
JSP Session
JSP redirection after session timeout
How to check if session exists?
session invalid problem