• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Session-logout button  RSS feed

 
Ranch Hand
Posts: 47
MySQL Database Spring Tomcat Server
  • 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?
 
Rancher
Posts: 1829
15
Android Eclipse IDE Java Java ME
  • 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
  • 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

 
Ranch Hand
Posts: 672
4
Eclipse IDE Java Spring
  • X Likes 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...
 
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • 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
  • 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
 
Author and ninkuma
Marshal
Posts: 66402
156
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
Ranch Hand
Posts: 38
Eclipse IDE Java Spring
  • 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
Posts: 66402
156
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using JavaScript for this is not good advice. JavaScript can easily be disabled.
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter
https://coderanch.com/t/690611/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!