Reputation: 29
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
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
Reputation: 116
I believe, i agree with answer given by chris g. However, i have few things to highlight for you.
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.
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