On Java Development

All things related to Java development, from the perspective of a caveman.

Managing Session Timeouts

without comments


This post shows how to manage the session timeout which is the expiration of the HTTP session after a specified period of time.

When a time-out occurs it makes the page inoperable leaving the user to believe the application is broken. More accurately, it is simply no longer communicating to the server. It becomes necessary to detect when the time-out occurs and to redirect to a web page informing the user the session time-out interval has been reached. At that time their only recourse is to restart the application as instructed. The bonus is that it prevents a call to the help-desk. The solution presented is in the context of JSF-Facelets using templates, but the idea is the same for applications based upon older JSP-HTML designs.

The Timeout Parameter Setting

The default value for a session time-out interval is 30 minutes. The timeout parameter shown below is contained in the web.xml file.

The JSF-Facelet Application Page Template

The pageTemplate.xhtml file shown below is used by all pages of the application. A new entry was added (line 13) to instruct the page to read the session’s maximum interval of inactivity value that was defined in the web.xml file. When the time interval is reached the timout.jsf page is automatically displayed.

The trouble is, the timeout.jsf will expire, too. This condition creates somewhat of an advantage, for it allows the user to be notified that their session has expired and if that page sits there for another 30 minutes there is a good chance no one is sitting in front of it anyway. In that case, the best thing to do is to send the browser back to the main menu. This is where the timeoutTemplate.xhtml comes into play.

The JSF-Facelet Timeout Template

Below is the timeoutTemplate.xhtml file but as seen on line 13, the page that is to display when the timeout occurs is the page from which the application was launched.

Both the pageTemplate.xhtml page and the timeoutTemplate.xhtml page presented above are placed under the resources directory as shown.

The Timeout.xhtml Page

The timeout.xhtml file shown below is also designed as a Facelet and uses the page template directly above.

The timeout.xhtml file is placed into the directory shown.

With these settings, when the web application is being used all pages will expire on a 30-minute time interval at which time the timeout.xhtml page will be presented. When this occurs, the user can then select the hyperlink to return to the home menu to relaunch the application. If this page is left alone for another 30 minutes, then the browser will return to the page from which the application was launched. That page is the same page referenced by the hyperlink.


For more information on Facelets and template files, see this link.

Written by admin

April 7th, 2014 at 7:49 am

Posted in Uncategorized

Leave a Reply

You must be logged in to post a comment.