Because an HTTP client has no way to signal that it no longer needs a session, each session has an associated timeout so that its resources can be reclaimed. The timeout period can be accessed by using a session’s getMaxInactiveInterval and setMaxInactiveInterval methods.
To ensure that an active session is not timed out, you should periodically access the session by using service methods because this resets the session’s time-to-live counter.
When a particular client interaction is finished, you use the session’s invalidate method to invalidate a session on the server side and remove any session data.
To set the timeout period in the deployment descriptor using NetBeans IDE, follow these steps.
Open the project if you haven’t already.
Expand the project’s node in the Projects pane.
Expand the Web Pages node and then the WEB-INF node.
Double-click web.xml.
Click General at the top of the editor.
In the Session Timeout field, type an integer value.
The integer value represents the number of minutes of inactivity that must pass before the session times out.