Can I control Session timeout?
Yes, you can change the session timeout in your application. By default, on most servers the session is set to expire after 30 minutes of inactivity. The amount of time can be configured in the deployment descriptor of the Web application. For example, to change the session timeout to one hour, add the following inside the <web-app> section:
<session-config>
<session-timeout>60</session-timeout>
</session-config>
The HttpSession API also provides a setMaxInactiveInterval() method that you can use to specify the timeout period for a session. The getMaxInactiveInterval() method will return this timeout value. The value given is in seconds.
-
public void setMaxInactiveInterval(int interval): Specifies the time, in seconds, between client requests before the servlet container will invalidate this session. A negative time indicates the session should never timeout. -
public int getMaxInactiveInterval(): Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. After this interval, the servlet container will invalidate the session. The maximum time interval can be set with the setMaxInactiveInterval method. A negative time indicates the session should never timeout.
The length of time will vary depending on what your visitors are doing on your site. If they're logging in to check their account balance, a shorter session timeout period can be used because it doesn't take long for a person to read a couple of numbers. If, on the other hand, the user is logging in to read large amounts of data, you need to be sure that you provide enough time for the user to do what he or she wants without being logged out. If the user is constantly navigating through your site, the session will last indefinitely.
Most Recent servlet Faqs
- How to get the client information in a Servlet?
- Can I control Session timeout?
- What is the difference between RequestDispatcher's forward method and HttpServletResponse's sendRedirect method?
- When do I use HttpSessionListener?
- What is the difference between the request attribute and request parameter?
- What is the defferent between getNamedDispatcher() and getRequestDispatcher()?
- How do you communicate in between applets and servlets?
Most Viewed servlet Faqs
- What is the difference between the request attribute and request parameter?(12100)
- When do I use HttpSessionListener?(11630)
- How to use ServletContext.getResourceAsStream(java.lang.String path)?(8249)
- What is the difference between RequestDispatcher's forward method and HttpServletResponse's sendRedirect method?(6880)
- Can I control Session timeout?(5293)
- What is the defferent between getNamedDispatcher() and getRequestDispatcher()?(4916)
- How to get the client information in a Servlet?(4477)