0
votes

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?

2

2 Answers

4
votes

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.

1
votes

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