• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can i distinguish between log out or session timeout?

 
harry lee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That greatly depends on what you mean by "logging out".
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Haha,i know now ,Thanks.
 
Akshay Kiran
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • 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.
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!