• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

javascript and session info

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to find out whether my session has timed out or not by using java script.and finally how much time is left for timeout and that i want to show as an alert.please help me with some code if possible..
[ March 01, 2006: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67746
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
Sorry. It is not possible.

Also, please be sure to use descriptive subject titles. I have taken the opportunity to change this one for you.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well its not directly possible, but you could do something like this on every page.

<script language="javascript">
var sessionTimeout = new Date( new Date().valueOf() + <%= session.getMaxInactiveInterval() %>);
</script>

You now have a javascript variable representing the date/time when the session on the server will expire.
You can use the javascript window.setTimeout or window.setInterval methods to call javascript after a certain amount of delay.
I'm sure you can figure out the rest from here.
[ March 02, 2006: Message edited by: Stefan Evans ]
 
Bear Bibeault
Sheriff
Posts: 67746
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
Except that the act of polling the session in this way resets the session timeout, making it ineffective for determining how much time is left on the session timeout.

I assumed that the OP was more interested in determining the amount of time remaining in the session as a result of user events on the page rather than at page load time when the answer will always be the length of the session timeout itself.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, guess I didn't make it clear.
Agreed: any access to a page resets the session timeout.

What I am suggesting is that you load into a javascript variable, the info you need to predict approximately when the session will time out
That being the maxInactiveInterval of the session.

Given this value in a javascript variable, you can perform javascript calculations as required. eg


If the user does not navigate off this page, it should call the javascript alertSessionExpiring() method approximately a minute before the session would expire. The user can then take action to keep their session alive (ie make a request)
[ March 02, 2006: Message edited by: Stefan Evans ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic