my dog learned polymorphism
The moose likes Servlets and the fly likes Session Time out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Time out" Watch "Session Time out" New topic

Session Time out

Murthy Ksn

Joined: Mar 07, 2008
Posts: 1
How to show an alert message when session time out, during application execution? Please let me know.
Naresh Rayakwar

Joined: Feb 15, 2010
Posts: 1
This application is web application or stand alone java application
David Newton

Joined: Sep 29, 2008
Posts: 12617

You'd have to poll the server (probably via Ajax and timer event) to find out--the server can't push this information to the client.
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 544
If we hit the server using Ajax then would not it keep the session alive on server?
Please correct me if I understood this wrong.

yogesh srinivasan
Ranch Hand

Joined: Jun 08, 2007
Posts: 55
In that case you cant use session time out method [setMaxInactivInterval].

1. Poll an AJAX request and manually calulate the timeout period

if(CurrentTime - HtpSession.getCreationTime - timeOut) = TIMEOUT - [alter_period]) {
sendalert response to rest timeout.
}else if(CurrentTime - HtpSession.getCreationTime - timeOut) = TIMEOUT){

2. write another filter resetTimeOut

if(request = isNot[AJAX timeout request]
- reset timeout variable

This is the best i got.
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

I am not sure if i have the answer but ...
when the session has timed out then the class that is implementing HttpSessionListener interface can do something.... given that you want to do something AFTER the session has timed out

Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

But one thing such a listener cannot do is to communicate with the client in any way. To issue an alert, for example.

The OP is thinking of the problem backwards. Upon a request, whether the session has expired of not can be checked (a filter is great for this). But if no request has been made, there's not much to be done.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Session Time out
It's not a secret anymore!