This week's book giveaway is in the JavaScript forum.
We're giving away four copies of JavaScript Promises Essentials and have Rami Sarieddine on-line!
See this thread for details.
The moose likes JSP and the fly likes JSP inactive session after few minutes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP inactive session after few minutes" Watch "JSP inactive session after few minutes" New topic
Author

JSP inactive session after few minutes

Santosh Ramachandrula
Ranch Hand

Joined: Apr 04, 2004
Posts: 252
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)?


Thanks,
Santosh
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
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

Joined: Apr 04, 2004
Posts: 252
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

Joined: Feb 08, 2005
Posts: 362


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

Joined: Jan 10, 2002
Posts: 61594
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
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

Joined: Jan 10, 2002
Posts: 61594
    
  67

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP inactive session after few minutes