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
Solved

How to Handle session time out in JSP?

Posted on 2011-02-24
7
1,693 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 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
console vs log file 16 82
Spring MVC - sending raw charset to backend 3 222
Java Script nested call 3 87
jsp login check 12 42
If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
Is your phone running out of space to hold pictures?  This article will show you quick tips on how to solve this problem.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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