Question: I need the sessions in my web application not to timeout. They should be there until the user log out manually. It might be a bad call but I must implement it.

I tried the below in web.xml

```
<session-config>
        <session-timeout>
            -1
        </session-timeout>
    </session-config>

```

However the session is still getting time out! Any suggestions?

Answer: 
You can do this too : 

```
<session-config>
    <session-timeout>0</session-timeout>
</session-config>

```

You can see how it works just [here](https://stackoverflow.com/questions/15382895/session-timeout-in-web-xml)
use a HttpSessionListener. In the sessionCreated() method, you can set the session timeout programmatically.

```
public class MyHttpSessionListener implements HttpSessionListener{
  public void sessionCreated(HttpSessionEvent event){
    event.getSession().setMaxInactiveInterval(-1); //in seconds
  }
  public void sessionDestroyed(HttpSessionEvent event){}
}
And don't forget to define the listener in the deployment descriptor:

<webapp>
...
  <listeners>
    <listener-class>com.MyHttpSessionListener</listener-class>
  </listeners>
</webapp>

```