Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to Handle session time out in JSP?

Posted on 2011-02-24
7
Medium Priority
?
1,805 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
  • 4
7 Comments
 
LVL 2

Accepted Solution

by:
ramkihardy earned 750 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 750 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Integration Management Part 2
Suggested Courses

916 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