- Using Hidden Controls
- The Cookie Class
- The HttpServletResponse Interface
- Creating a Cookie
- Reading a Cookie
- Setting and Reading a Cookie in the Same Page
- Using Sessions
- Creating a Session
- Setting Session Timeouts
- Using Applications
- Using Sessions, Applications, and JavaBeans
Setting Session Timeouts
You can use methods of the session object to set the maximum time between page accesses before the server ends the session:
getMaxInactiveInterval()Returns the maximum time interval, in seconds, for which the server will keep this session open between accesses.
setMaxInactiveInterval(int interval)Specifies the time, in seconds, between user requests before the servlet container will invalidate this session.
If you set the lifetime of a session to -1, the session will never expire.
The default timeout between user accesses for sessions in Tomcat is 30 minutes. You can change this in Tomcat's web.xml file (stored as jakarta-tomcat-4.0.3\conf\web.xml). All you have to do is change the time stored in the <session-timeout> element:
<!-- ==================== Default Session Configuration ================= --> <!-- You can set the default session timeout (in minutes) for all newly --> <!-- created sessions by modifying the value below. --> <session-config> <session-timeout>30</session-timeout> </session-config>
Besides sessions, you can also use applications.