Set the session timeout duration in Java.

In Java, you can use the setMaxInactiveInterval method to set the timeout time (expiration time) for the session in seconds.

Here is an example:

// 获取当前session
HttpSession session = request.getSession();

// 设置session的超时时间为30分钟
session.setMaxInactiveInterval(1800); // 30分钟 = 30 * 60秒

In the above example, the session timeout is set to 30 minutes (1800 seconds) by calling the setMaxInactiveInterval method. The session will automatically expire if there is no activity within 30 minutes.

Note: By default in Java, the session timeout is set to 30 minutes. It can be adjusted as per requirement.

bannerAds