Pavithra
Pavithra

Reputation: 29

Setting session timeout without web.xml in java web application

Is it possible to set session timeout without setting in web.xml or servlet for java web application? <session-config> <session-timeout>60(time in minutes)</session-timeout> </session-config>
And how to read .txt file which contains time and give its value to set session-timeoout in web.xml?

Upvotes: 0

Views: 2135

Answers (2)

chris g
chris g

Reputation: 1108

In web.xml:

<session-config>
        <session-timeout>60</session-timeout>
</session-config>

Programmatically:

session.setMaxInactiveInterval(60)

And as for reading in the value of a text file, you could use a properties file (named anything you want) and load it from there using the built-in Java Properties classes.

Note, the numbers above are in minutes.

Upvotes: 4

Rishav Mishra
Rishav Mishra

Reputation: 116

I believe, i agree with answer given by chris g. However, i have few things to highlight for you.

  1. The effect of session time out in web.xml is global and applicable to all the sessions. But, setMaxInactiveInterval is a non static method and has effect of a particular session.

  2. Setting 0 or less in session timeout tag in web.xml does not give any session timeout. But, setting 0 in setMaxInactiveInterval will immediate start closing the session.

Apart from this, setMaxInactiveInterval has same effect as session timeout tag except you can programmatically set session time out.

Thanks

Upvotes: 1

Related Questions