• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1845
  • Last Modified:

How to Handle session time out in JSP?

Hi All,

I am having a problem with session time out, can anyone please suggest me on how to handle session time out using spring. I am using weblogic as app server. I want to throw an error page when session has timed out.

Gangadhara Melukote
Gangadhara Melukote
  • 4
2 Solutions
This works for me

<session-management invalid-session-url="/taac/login">
    <concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />

Here's how I typically do it. On every AJAX call, check the result before using it.

$.ajax({ type: 'GET',
    url: GetRootUrl() + '/services/dosomething.ashx',
    success: function (data) {
      if (HasErrors(data)) return;

      // process data returned...

    error: function (xmlHttpRequest, textStatus) {
And then the HasErrors() function looks like this, and can be shared on all pages.

function HasErrors(data) {
  // check for redirect to login page
  if (data.search(/login\.aspx/i) != -1) {
    top.location.href = GetRootUrl() + '/login.aspx?lo=TimedOut';
    return true;
  // check for IIS error page
  if (data.search(/Internal Server Error/) != -1) {
    ShowStatusFailed('Server Error.');
    return true;
  // check for our custom error handling page
  if (data.search(/Error.aspx/) != -1) {
    ShowStatusFailed('An error occurred on the server. The Technical Support Team has been provided with the error details.');
    return true;
  return false;

If this is useful mark it as solution
With Regards............
Sathish David Kumar NArchitectCommented:
Put this code in your web.xml file

add this line in ur dispatcher servlert xml

Put some property entry which go to your sessionexpiry page or login page
Sathish David Kumar NArchitectCommented:
or use Interceptor concept to redirect ur login page the have perhandling and post handling method so it will check every time your session and redirect to original page or session expiry page
Sathish David Kumar NArchitectCommented:
User didnt mention his solution .  I have mention the correct solution .
Sathish David Kumar NArchitectCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now