aspose file tools*
The moose likes Servlets and the fly likes Java Session-logout button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Java Session-logout button" Watch "Java Session-logout button" New topic
Author

Java Session-logout button

Divya Chandel
Ranch Hand

Joined: Jun 09, 2011
Posts: 46

Hello All,

I am using MVC for my project and my problem is like this:
I would like to have the user redirected to login page when clicking 'back' button after logging out.
I am aware that clicking back button will give the user a copy of the previous page stored in the browser's cache.
So what I did:-



Is there any way that when a user logs out and tries to go to a 'cached page' through the 'Back' button be routed to the login page first?

Divya
SCJP1.6
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

When the user loggs in you may store the userinfo in a session scoped variable, and the user loggs out you can remove this attribute from session. Now, when the user navigates to any page, you can check whether you have user info in session scope or else redirect the user to login page. This is my though there can always be better options.


Swastik
Divya Chandel
Ranch Hand

Joined: Jun 09, 2011
Posts: 46

Swastik Dey wrote:When the user loggs in you may store the userinfo in a session scoped variable, and the user loggs out you can remove this attribute from session. Now, when the user navigates to any page, you can check whether you have user info in session scope or else redirect the user to login page. This is my though there can always be better options.


yes I did the same


and in logout


and put below code in each jsp page

Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 538

Divya Chandel wrote:

and put below code in each jsp page


Writing java code in JSP, is a very bad practice and is discredited for a decade now. Use JSTL.

Also, I would suggest you to read about servlet filters, instead using the java code in JSP to check for user has been logged in or not...
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2409
    
  28

Divya,

Do you have the response headers set on every page? Is this problem specific to a browser?
Divya Chandel
Ranch Hand

Joined: Jun 09, 2011
Posts: 46

Jayesh A Lalwani wrote:Divya,

Do you have the response headers set on every page? Is this problem specific to a browser?


No Jayesh, I set response headers only on index page, I mean Login Page, and it's not browser specific
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Putting Java code on every page is not good advice. I would pay attention to the advice that Prasad Krishnegowda is giving you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vivek SharmaJi
Ranch Hand

Joined: Dec 09, 2012
Posts: 38

Hi Divya, You can take some javascript variable and set value 0 to 1 when user logs out, then you detect browser back button using javascript and call a logout function. I mean you can check if browser back button was clicked and your variable value was also 1, when both these conditions are true, you call logout function.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Using JavaScript for this is not good advice. JavaScript can easily be disabled.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Session-logout button