saplingPro
saplingPro

Reputation: 21329

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.

Upvotes: 4

Views: 7386

Answers (2)

Sky
Sky

Reputation: 99

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.

Upvotes: 2

adarshr
adarshr

Reputation: 62603

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.

Upvotes: 7

Related Questions