• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

JSP inactive session after few minutes

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Folks,
Is there a way to detect

1. If a browser session has been inactive for 5 minutes (eg: user opened the page and left)(session time out is set to 30 mins)

2. If the user has closed a browser and can I detect that the user has been inactive after 5 mins (session time out is set to 30 mins)?
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Define "inactive"
Is it not browsing from the page, or not doing anything at all (eg moving the mouse)
Where do you want to detect this? On the browser, or on the server?

For the first:
On the page you can use a javascript call to window.setTimeOut( "doSomethingAfter5Minutes()", 300000);
If the user stays on that page for 5 minutes (300,000 milliseconds) then that javascript will be evaluated/run. That will only be on the client side.

On the server side of things, you can't tell anything except the last time the user made a request. The browser could be closed, or it could just be sitting there unused. There is no way to tell from the server side.
Thats the whole point of a session timeout.
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stefan,
Thanks for your response. From what you said server side detection is ruled out. As far as javascript is considered regardless of what user does after 5 mins the Javascript will be evaluated. So either case I can't detect the idleness of page? Right?
 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


That should do the trick in your web.xml file.

If the browser is closed the session cookie expires automatically and thus the session is killed right there.
 
Sheriff
Posts: 67693
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

Originally posted by Gerardo Tasistro:

... and thus the session is killed right there.



Not quite. The session, knowing nothing about what's going on on the client, remains in scope until its timeout expires.

The session is "orphaned" because the cookie goes away, but it is not "killed".
[ March 31, 2006: Message edited by: Bear Bibeault ]
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, in server session state. But with client or dbase state it is dead. I think it is better to consider it dead once the browser closes. Sure the resources are still there, but without the session ID you're out of luck.
 
Bear Bibeault
Sheriff
Posts: 67693
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
It's orphaned but not "dead". I see no utility in trying to mislead people to think that it is. The session, and any resources it is holding remains in scope until the session timeout.
 
reply
    Bookmark Topic Watch Topic
  • New Topic