Solved

How to Handle session time out in JSP?

Posted on 2011-02-24
7
1,715 Views
Last Modified: 2012-05-11
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.

Thanks
Pavan
0
Comment
Question by:Gangadhara Melukote
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 
LVL 2

Accepted Solution

by:
ramkihardy earned 250 total points
ID: 34968273
This works for me

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

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) {
      ShowStatusFailed(xmlHttpRequest);
    }
  });
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............
0
 
LVL 20

Assisted Solution

by:Sathish David Kumar N
Sathish David  Kumar N earned 250 total points
ID: 34968482
Put this code in your web.xml file
       <session-config>      
                 <session-timeout>180</session-timeout>  
             </session-config>

add this line in ur dispatcher servlert xml

Put some property entry which go to your sessionexpiry page or login page
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34968505
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
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35147051
User didnt mention his solution .  I have mention the correct solution .
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35221433
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A hard and fast method for reducing Active Directory Administrators members.
By reading this blog, MSPs will gain insight into how to improve communications with their clients as well as establish a more profitable business.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question