Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For how long does a session last by default?

For how long does a session :

HttpSession session = request.getSession();

last when I do not explicitly declare session.setMaxInactiveInterval(int i)? Let us assume, the user doesn't delete the cookies from his browser.

like image 281
saplingPro Avatar asked Jan 15 '23 18:01

saplingPro


2 Answers

As long as the declared value of session-timeout in web.xml states. If there is no value specified there, the container decides this setting.

like image 200
adarshr Avatar answered Jan 28 '23 05:01

adarshr


HttpSession has getMaxInactiveInterval method which can tell you how much the session will stay available for the user.

If you setMaxInactiveInterval to a negative number it'll never expire as long as he doesn't delete cookies.

EDIT : For your commentary on the other answer where I can't add a comment, if the user doesn't accept cookies, he'll never have a session. So if he deletes it, he'll start a new session.

like image 41
Sky Avatar answered Jan 28 '23 04:01

Sky