本文整理汇总了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;
}