Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javascript and session info

 
sudeshna de
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Stefan Evans
Bartender
Pie
Posts: 1670
10
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 1670
10
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic