• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Case: Scenario - Session Time out.

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 74054
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 22457
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the HttpSession for this.

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.
 
Mezan Shareef
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys. !! I am trying would update if i succeeded
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic