Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the remaining session time? [closed]

Tags:

java

jquery

ajax

I have a dynamic web project in Java using Hibernate, servlets and JSP. I want to get the remaining session time for a client so that I can warn them of the upcoming session expiration.

For example, the user would login to the application with one minute of session time. When the remaining session time is ten seconds, I want to warn the user using AJAX and JQuery. How would I do this?

like image 537
Semih Okan Pehlivan Avatar asked Aug 07 '14 12:08

Semih Okan Pehlivan


People also ask

How do I check my session timeout?

The Session Timeout setting is found on the Global Settings page, in the Security tab. This setting is used to control how long a user session can be inactive in their browser before they are automatically redirected to a pop-up Login window.

How long is session timeout?

Typical session timeouts are 15- to 45-minute durations depending on the sensitivity of the data that may be exposed. As the session timeout is approaching, offer users a warning and give them an opportunity to stay logged in.

What is session default timeout?

The default is 10 minutes. Session. Timeout has no hard-coded limit. Most Web administrators set this property to 8 minutes. It should not be set higher than 20 minutes (except in special cases) because every open session is holding onto memory.


2 Answers

You can make use of HTTPSession.

  • getLastAccessedTime() : returns the time session was last accessed
  • getMaxInactiveInterval() : returns the timeout period.

Make use of current time and apply logic.

like image 160
Jayarajan Avatar answered Oct 09 '22 10:10

Jayarajan


Well you cannot actually get session time with an AJAX request as the request it self will also reset the session timeout time. What you can do is get it when you are rendering the page in a js function and start a counter with setTimeout when and show your message pop when less then 30 seconds left.

like image 32
Onur Topal Avatar answered Oct 09 '22 11:10

Onur Topal