Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP inactive session after few minutes

 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • 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)?
 
Stefan Evans
Bartender
Posts: 1751
10
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64971
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64971
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic