Forums Register Login

Can i distinguish between log out or session timeout?

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
That greatly depends on what you mean by "logging out".
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Haha,i know now ,Thanks.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2995 times.
Similar Threads
SessionListener
How should i keep user info after successful login?
jboss session time out listener
session time out
How to ge know which users are using an app?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:59:53.