Skip to content

Synchronizing Client and Server Side Timeouts

January 23, 2012

We needed a flashy client-side session timeout warning and chose jQuery Idle Timeout.  We were, however, unhappy with maintaining the timeout value in both the javascript and in web.xml.  The latter is necessary to enforce the session timeout when javascript is off or if tampered with via GreaseMonkey or similar.  We employed a simple strategy to keep things a bit more DRY: generate the javascript timeout value on the serverside via session.getMaxInactiveInterval(), e.g.

<%@ page session="true"%>

<script type="text/javascript">
  // start the jQuery Idle Timeout plugin
  $.idleTimeout('#dialog', 'div.ui-dialog-buttonpane button:first', {
	idleAfter: <%= session.getMaxInactiveInterval() %>, 

This approach is not specific to this jQuery plugin; any client side timeout can use this method. Also, it has the nice quality of respecting any changes made through an application server console, e.g. temporarily overriding the value seeded by in web.xml.


From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s