File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Session-logout button

 
Divya Chandel
Ranch Hand
Posts: 47
MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Divya Chandel
Ranch Hand
Posts: 47
MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 665
4
Eclipse IDE Java Spring
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Divya,

Do you have the response headers set on every page? Is this problem specific to a browser?
 
Divya Chandel
Ranch Hand
Posts: 47
MySQL Database Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Putting Java code on every page is not good advice. I would pay attention to the advice that Prasad Krishnegowda is giving you.
 
Vivek SharmaJi
Ranch Hand
Posts: 38
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using JavaScript for this is not good advice. JavaScript can easily be disabled.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic