• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Session-logout button

 
Ranch Hand
Posts: 47
MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using JavaScript for this is not good advice. JavaScript can easily be disabled.
 
reply
    Bookmark Topic Watch Topic
  • New Topic