In my web application , am annotation based controllers (SPRING MVC). I wanted to implement SessionManagement in my application
1.) Any page within the application should not be idle for 15 minutes
2.) Pop-up should be opened, kind-of notification, at the 10th minute to notify the user abt session expiry and should give him an option to extend the session to another 15 minutes or by default the application should log-off
I believe there must be a simple way for this in spring MVC (I use spring 3.1). Say like, there must be some way to annotate the controller or some configuration in applicationContext.xml. There must be some way ! Friends, please help me by suggesting a way and also would be of great help if you paste any samples here. Also would be of great help if you can guide me step-by-step for this sessionManagement implementation.
Spring MVC has little to do here. Suppose you have a session timeout set to 15 minutes. Simply place the following JavaScript code on every page on your site and run it after the page is loaded:
function expireWarning() {
if(confirm("Your session will expire in 5 minutes, extend?")) {
$.ajax('/echo/json/');
setTimeout(expireWarning, 10 * 60 * 1000);
}
}
setTimeout(expireWarning, 10 * 60 * 1000);
That's it! After 10 minutes pop-up will appear. If the user confirms, AJAX request will be send to the server, automatically extending the session. The counter is then rescheduled to ask the user after another 10 minutes.
Note that the AJAX target on the server doesn't have to do anything. The only purpose of this call is to tell the container that the user is still using this session token.
Another tip: if your site is already using AJAX, you must reschedule the timeout after every call because every AJAX call extends the session as well. If the user stays on the site and triggers a lot of AJAX calls, the session is extended over and over automatically.