本文整理匯總了Java中javax.servlet.http.HttpSession.getMaxInactiveInterval方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpSession.getMaxInactiveInterval方法的具體用法?Java HttpSession.getMaxInactiveInterval怎麽用?Java HttpSession.getMaxInactiveInterval使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.servlet.http.HttpSession
的用法示例。
在下文中一共展示了HttpSession.getMaxInactiveInterval方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setSessionMaxInactiveInterval
import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
/**
* Sets the maximum inactive interval (session timeout) an HttpSession
* @param sessionId
* @param maxInactiveInterval in seconds
* @return old value for maxInactiveInterval
* @throws IOException
*/
public int setSessionMaxInactiveInterval(String path, String sessionId, int maxInactiveInterval) throws IOException {
HttpSession session = getSessionForPathAndId(path, sessionId).getSession();
if (null == session) {
// Shouldn't happen, but let's play nice...
if (debug >= 1) {
log("WARNING: can't set timout for null session " + sessionId);
}
return 0;
}
try {
int oldMaxInactiveInterval = session.getMaxInactiveInterval();
session.setMaxInactiveInterval(maxInactiveInterval);
return oldMaxInactiveInterval;
} catch (IllegalStateException ise) {
if (debug >= 1) {
log("Can't set MaxInactiveInterval '" + maxInactiveInterval + "' for invalidated session id " + sessionId);
}
return 0;
}
}
示例2: destroyInactiveSessions
import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
@Override
public void destroyInactiveSessions() {
for (Map.Entry<String, HttpSession> entry : sessions.entrySet()) {
HttpSession session = entry.getValue();
if (session.getMaxInactiveInterval() < 0)
continue;
long currentMillis = System.currentTimeMillis();
if (currentMillis - session.getLastAccessedTime() > session.getMaxInactiveInterval() * 1000) {
session.invalidate();
destroySession(entry.getKey());
}
}
}
示例3: getInterval
import javax.servlet.http.HttpSession; //導入方法依賴的package包/類
/**
* @return the interval of keepAlive tag
*/
public Long getInterval() {
if (interval == null) {
FacesContext ctx = getFacesContext();
HttpSession httpSession = (HttpSession) ctx.getExternalContext()
.getSession(false);
int maxInactiveInterval = httpSession.getMaxInactiveInterval();
// To keep session alive, the interval value is 1 minute less than
// session timeout.
long intervalValue = (long) maxInactiveInterval * 1000 - 60000L;
interval = Long.valueOf(intervalValue);
}
return interval;
}