2012-11-05 44 views

回答

2

所以,你已經一個HttpSession在手,無需具體HttpServletRequest

可以current inactive timemax inactive interval的總和遞增max inactive interval

int maxInactiveInterval = session.getMaxInactiveInterval(); 
int currentInactiveTime = (int) (System.currentTimeMillis() - session.getLastAccessedTime()/1000); 
session.setMaxInactiveInterval(maxInactiveInterval + currentInactiveTime); 

然而,這需要一些filter再次重置它返回到默認的最大非活動時間間隔在每次請求時它的值從默認是關閉的。

session.setMaxInactiveInterval(defaultMaxInactiveInterval); 

對於Servlet 3.0,此值可通過SessionCookieConfig#getMaxAge()獲得。

int defaultMaxInactiveInterval = getServletContext().getSessionCookieConfig().getMaxAge();