• 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

Can i distinguish between log out or session timeout?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Can i distinguish between the log out or the session timeout?By this,i can insert session timeout infomation into log table.When it is user log out ,i can insert "user log out" int to log table.So,can i use listener to make this work?
Thanks.
 
Sheriff
Posts: 67746
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
That greatly depends on what you mean by "logging out".
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that log out means you user clicks on the logout link provided in the frontend.

In this case case you explicitly call session's invalidate method and once this call is done the sessionDestroyed method of HttpSessionListener is called.
In case of timeout this is not the case and the HttpSessionListener's sessionDestroyed is called directly on timeout.

The possible solution i see here is to write to db before calling the invalidate method for logout and in sessionDestroyed check if any entry was made in db, if not its a session timeout.
 
harry lee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Haha,i know now ,Thanks.
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just a passing thought.

are you trying to simulate the situation where a user keeps his browser open for a long time, and then clicks on link
and sees
"Sorry your session has timed out"
and in cases he has explicitly logged out, he sees the login page?

one way I see to achieve this is-
in the first case, the browser sends in a JSESSIONID in the cookie header that refers to a nonexistent session. therefore getSession(false) would return null
in the second case, neither is such a header sent, nor is the session available.
if i am not mistaken that is...
i might be missing something here- haven't thought on these lines for a long time.
so you could probably insert a filter that does this check.
 
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you may have a flag which indicates weather a user has logged out or not.
you can set this flag when user clicks on logout link.
in the case of session timeout this flag will not be set so you can figure out that its session time out.

What you can do is, when there is no session exists for a user, you can check if the flag is set, if its set than it means user had successfully logged out last time. if it is not it indicated session time out.
you can write a filter for that.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic