Hi friends how are you all. Hope you are all doing good. here is my question.
Lets say i have an ecommerce website, which is a link in another website (Not mine) where people come to buy some household items. If user stays on website for 30 minutes with no activity. I need to display that user that session has expired.
How can i go about it.?
Note: there is single sign on. people do not log into mywebsite, people log into others website, but there is link in that website so a new page of my website opens..
please shed some light. sugestions, comments, views, opinions, everything welcomed.
Don't know. On a Swing application you could have some sort of timer, or a thread which sleeps for 1000ms at a time. Also a key listener; whenever any key is pushed, the last time used is recorded. When the system time found by your sleeping thread is >30000ms more than the last time used, you can fire another listener to log out. But don't know what you would do on the web; maybe you should provide more details of how it works.
Anyway, this looks too difficult for "beginning", so I shall move it. Let's try "JIG" first, but your discussion might be moved again.
A naive approach would be to set the web application's session timeout to 30 minutes, then check the isNew() method. If the old session has expired a new session would be created, so isNew() would return true. However, it will also return true on the first visit.
Another approach is to use a session attribute that stores when the user was active the last time. This gets queried with each request, then overwritten with the current date/time. A java.util.Date object would work nicely; the result from its getTime() method can be compared to System.currentTimeMillis(), and expired then means that the difference > 30 * 60 * 1000. Note that the querying before overwriting order is important Also, the Date may be absent if the HttpSession itself has expired or hasn't been created yet.
You could use a Filter to perform the checking. A simple approach:
Now all you need to do is check if the session's expired attribute equals Boolean.TRUE to display the message or not.
You may want to make these attribute keys public static final String constants though.