I am using spring security, java in application. When the session gets expired, I need to show an alert that the session is over. The box should have an ok button which, when clicked, I want to redirect to login page.where should i put max time out and display alert message after time out.
Assuming that the session timeout timer is reset once a new page is loaded, you can simply use a JavaScript timeout:
setTimeout(function() {
if(confirm('session timeout'))
location.href = 'login.html';
}, 15 * 60 * 1000); // 15 minutes, alter appropriately
As soon as you navigate to another page, all current JavaScript is discarded, so the timeout will be reset.
if its an ajax-enabled website, check for auth/session on every ajax-request, return statuscode or similar on the request, and do a check for that on the client side. If statuscode 401, display alert.
I dont see the need to have a timer to trigger it after an idle period, to be honest.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.