• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

notifying the timeout to client

 
shan subramaniam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I want to notify the user that their "session is above to expire click ok to continue" when the user clicks OK the session timeout should be reset
unfortunately i can't use JavaScript.
Is there any push mechanism instead of pull?

The project environment is j2ee1.4,struts 1.2 and extensive use of tiles with multiple windows wizard like application

I will really appreciate it if there is any suggestions
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. How would the server even know whether the browser was loaded with a page from the web app or not?
 
shan subramaniam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear Thanks for the immediate response
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shan said:
unfortunately i can't use JavaScript.


Any reason why you cant use javascript?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would JavaScript know that the session was about to time out? It can make a rough guess but can't know for sure. And if there are other windows (frames, iframes, child windows) all bets are off because any one of those can hit the server and extend the session lifetime.
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
How would JavaScript know that the session was about to time out? It can make a rough guess but can't know for sure. And if there are other windows (frames, iframes, child windows) all bets are off because any one of those can hit the server and extend the session lifetime.


You can initialise javascript variable with session timeout value using JSP.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
How would JavaScript know that the session was about to time out? It can make a rough guess but can't know for sure. And if there are other windows (frames, iframes, child windows) all bets are off because any one of those can hit the server and extend the session lifetime.


Cant we do something like this?
When the session is created i store the time it was created in the session as an attribute (using HttpSessionListener). Then from the browser after a regular interval send a request to a servlet using say XMLHttpObject. There i check the current time and the time i stored the attribute when the session was created. Check that difference and send an appropriate code or message and on the browser side i use that to show a message to the user. Shouldnt this take care even if multiple windows are open (sharing the same session)?
[ November 26, 2008: Message edited by: Amol Nayak ]
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amol Nayak:


Cant we do something like this?
When the session is created i store the time it was created in the session as an attribute (using HttpSessionListener). Then from the browser after a regular interval send a request to a servlet using say XMLHttpObject. There i check the current time and the time i stored the attribute when the session was created. Check that difference and send an appropriate code or message and on the browser side i use that to show a message to the user. Shouldnt this take care even if multiple windows are open (sharing the same session)?

[ November 26, 2008: Message edited by: Amol Nayak ]

No, you can't. Everytime you make a call the session becomes active again, hence won't time out until after the next interval.

javascript function window.setTimeout would do the job perfectly with the timeout value comes from session attribute "maxInactiveInterval".
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posted by Duc Vo
No, you can't. Everytime you make a call the session becomes active again, hence won't time out until after the next interval.

The session was never inactive, it was always active unless someone invalidates it as the interval after which we make the call is less than the max inactive interval we set in web.xml (if we have set one)

If you requirement is to notify the client after say 20 mins of login then
your requirement can be achieved by explicitly invalidating the session when the user does not wish to extend the session or does not respond for extending the session and the timeout interval is reached. (This timeout is not the timeout specified in session-config of web.xml).
[ November 27, 2008: Message edited by: Amol Nayak ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Duc Vo:
You can initialise javascript variable with session timeout value using JSP.
That does not account for the other factors I listed.

As I said, you can make a rough guess, but you cannot exactly know when the session will time out.

A better approach to the annoying "your session is about to time out" messages is to make sure that there are no consequences to timing out. For example, if a user times out during an operation, be sure that you can resume that operation automatically after they re-authenticate.
[ November 27, 2008: Message edited by: Bear Bibeault ]
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
That does not account for the other factors I listed.

As I said, you can make a rough guess, but you cannot exactly know when the session will time out.

A better approach to the annoying "your session is about to time out" messages is to make sure that there are no consequences to timing out. For example, if a user times out during an operation, be sure that you can resume that operation automatically after they re-authenticate.

I agree though if you want absolute answer you would also have to factor the network delay time as well. However, in this case it seems you are over complicating the problem. The original request doesn't mention the complexity of the page it would be safe to assume that it is simple enough to be managable. Also the response message is for end user as of information message, not to another system. The accuracy should be to the minute not to the milisecond. I would guess javascript is OK to use.

Another solution (only work for GET page) is to set the page meta tag to refresh itself after the session interval time, if the session is expired direct user to an information page.

Originally posted by Amol Nayak:

The session was never inactive, it was always active unless someone invalidates it as the interval after which we make the call is less than the max inactive interval we set in web.xml (if we have set one)

Sorry I used a wrong word "active". But anyway, the idea is that if you keep calling to ask if the session expired within the max inactive interval time, it will never expired.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic