javax.servlet.http.HttpSession.setMaxInactiveInterval()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(233)

本文整理了Java中javax.servlet.http.HttpSession.setMaxInactiveInterval()方法的一些代码示例,展示了HttpSession.setMaxInactiveInterval()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpSession.setMaxInactiveInterval()方法的具体详情如下:
包路径:javax.servlet.http.HttpSession
类名称:HttpSession
方法名:setMaxInactiveInterval

HttpSession.setMaxInactiveInterval介绍

[英]Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.

An interval value of zero or less indicates that the session should never timeout.
[中]指定servlet容器使此会话无效之前客户端请求之间的时间(秒)。
间隔值为零或更小表示会话不应超时。

代码示例

代码示例来源:origin: perwendel/spark

/**
 * Specifies the time, in seconds, between client requests the web container will invalidate this session.
 *
 * @param interval the interval
 */
public void maxInactiveInterval(int interval) {
  session.setMaxInactiveInterval(interval);
}

代码示例来源:origin: jfinal/jfinal

public void setMaxInactiveInterval(int maxInactiveInterval) {
  session.setMaxInactiveInterval(maxInactiveInterval);
}

代码示例来源:origin: jfinal/jfinal

public void setMaxInactiveInterval(int maxInactiveInterval) {
  session.setMaxInactiveInterval(maxInactiveInterval);
}

代码示例来源:origin: Atmosphere/atmosphere

private synchronized void refreshTimeout(HttpSession session) {
  if (requestCount.get() > 0)
    session.setMaxInactiveInterval(internalSessionTimeout);
  else
    session.setMaxInactiveInterval(timeout);
}

代码示例来源:origin: gocd/gocd

@Override
  protected void doFilterInternal(HttpServletRequest request,
                  HttpServletResponse response,
                  FilterChain chain) throws ServletException, IOException {
    boolean hadNoSessionBeforeStarting = request.getSession(false) == null;
    try {
      chain.doFilter(request, response);
    } finally {
      HttpSession session = request.getSession(false);
      boolean hasSessionNow = session != null;

      if (hadNoSessionBeforeStarting && hasSessionNow) {
        LOGGER.debug("Setting max inactive interval for request: {} to {}.", request.getRequestURI(), maxInactiveInterval);
        session.setMaxInactiveInterval(maxInactiveInterval);
      }
    }
  }
}

代码示例来源:origin: apache/shiro

public void setTimeout(long maxIdleTimeInMillis) throws InvalidSessionException {
  try {
    int timeout = Long.valueOf(maxIdleTimeInMillis / 1000).intValue();
    httpSession.setMaxInactiveInterval(timeout);
  } catch (Exception e) {
    throw new InvalidSessionException(e);
  }
}

代码示例来源:origin: spring-projects/spring-session

@Override
public final void loginSuccess(HttpServletRequest request,
    HttpServletResponse response, Authentication successfulAuthentication) {
  if (!this.alwaysRemember
      && !rememberMeRequested(request, this.rememberMeParameterName)) {
    logger.debug("Remember-me login not requested.");
    return;
  }
  request.setAttribute(REMEMBER_ME_LOGIN_ATTR, true);
  request.getSession().setMaxInactiveInterval(this.validitySeconds);
}

代码示例来源:origin: cloudfoundry/uaa

@Override
public void onApplicationEvent(HttpSessionCreatedEvent event) {
  logger.debug("Setting session timeout["+event.getSession().getId()+"] to :"+timeout);
  event.getSession().setMaxInactiveInterval(timeout);
}

代码示例来源:origin: apache/geode

case SET_MAX_INACTIVE:
 session = request.getSession();
 session.setMaxInactiveInterval(Integer.valueOf(value));
 break;
case GET:

代码示例来源:origin: DeemOpen/zkui

Map<String, Object> templateParam = new HashMap<>();
HttpSession session = request.getSession(true);
session.setMaxInactiveInterval(Integer.valueOf(globalProps.getProperty("sessionTimeout")));

代码示例来源:origin: spring-projects/spring-session

@Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    wrappedRequest.getSession().setMaxInactiveInterval(interval);
    assertThat(wrappedRequest.getSession().getMaxInactiveInterval())
        .isEqualTo(interval);
  }
});

代码示例来源:origin: spring-projects/spring-session

@Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    HttpSession session = wrappedRequest.getSession();
    session.invalidate();
    // no exception
    session.getMaxInactiveInterval();
    session.setMaxInactiveInterval(3600);
  }
});

代码示例来源:origin: cloudfoundry/uaa

@Test
public void testDefaultTimeout() {
  listener.onApplicationEvent(event);
  verify(session, times(1)).setMaxInactiveInterval(30 * 60);
}

代码示例来源:origin: spring-projects/spring-session

@Test
public void loginSuccessWithAlwaysRemember() {
  HttpServletRequest request = mock(HttpServletRequest.class);
  HttpServletResponse response = mock(HttpServletResponse.class);
  Authentication authentication = mock(Authentication.class);
  HttpSession session = mock(HttpSession.class);
  given(request.getSession()).willReturn(session);
  this.rememberMeServices = new SpringSessionRememberMeServices();
  this.rememberMeServices.setAlwaysRemember(true);
  this.rememberMeServices.loginSuccess(request, response, authentication);
  verify(request, times(1)).getSession();
  verify(request, times(1)).setAttribute(
      eq(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR), eq(true));
  verify(session, times(1)).setMaxInactiveInterval(eq(2592000));
  verifyZeroInteractions(request, response, session, authentication);
}

代码示例来源:origin: spring-projects/spring-session

@Test
public void loginSuccess() {
  HttpServletRequest request = mock(HttpServletRequest.class);
  HttpServletResponse response = mock(HttpServletResponse.class);
  Authentication authentication = mock(Authentication.class);
  HttpSession session = mock(HttpSession.class);
  given(request.getParameter(eq("remember-me"))).willReturn("true");
  given(request.getSession()).willReturn(session);
  this.rememberMeServices = new SpringSessionRememberMeServices();
  this.rememberMeServices.loginSuccess(request, response, authentication);
  verify(request, times(1)).getParameter(eq("remember-me"));
  verify(request, times(1)).getSession();
  verify(request, times(1)).setAttribute(
      eq(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR), eq(true));
  verify(session, times(1)).setMaxInactiveInterval(eq(2592000));
  verifyZeroInteractions(request, response, session, authentication);
}

代码示例来源:origin: spring-projects/spring-session

@Test
public void loginSuccessWithCustomValidity() {
  HttpServletRequest request = mock(HttpServletRequest.class);
  HttpServletResponse response = mock(HttpServletResponse.class);
  Authentication authentication = mock(Authentication.class);
  HttpSession session = mock(HttpSession.class);
  given(request.getParameter(eq("remember-me"))).willReturn("true");
  given(request.getSession()).willReturn(session);
  this.rememberMeServices = new SpringSessionRememberMeServices();
  this.rememberMeServices.setValiditySeconds(100000);
  this.rememberMeServices.loginSuccess(request, response, authentication);
  verify(request, times(1)).getParameter(eq("remember-me"));
  verify(request, times(1)).getSession();
  verify(request, times(1)).setAttribute(
      eq(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR), eq(true));
  verify(session, times(1)).setMaxInactiveInterval(eq(100000));
  verifyZeroInteractions(request, response, session, authentication);
}

代码示例来源:origin: spring-projects/spring-session

@Test
public void loginSuccessWithCustomParameter() {
  HttpServletRequest request = mock(HttpServletRequest.class);
  HttpServletResponse response = mock(HttpServletResponse.class);
  Authentication authentication = mock(Authentication.class);
  HttpSession session = mock(HttpSession.class);
  given(request.getParameter(eq("test-param"))).willReturn("true");
  given(request.getSession()).willReturn(session);
  this.rememberMeServices = new SpringSessionRememberMeServices();
  this.rememberMeServices.setRememberMeParameterName("test-param");
  this.rememberMeServices.loginSuccess(request, response, authentication);
  verify(request, times(1)).getParameter(eq("test-param"));
  verify(request, times(1)).getSession();
  verify(request, times(1)).setAttribute(
      eq(SpringSessionRememberMeServices.REMEMBER_ME_LOGIN_ATTR), eq(true));
  verify(session, times(1)).setMaxInactiveInterval(eq(2592000));
  verifyZeroInteractions(request, response, session, authentication);
}

代码示例来源:origin: cloudfoundry/uaa

@Test
public void testNonDefaultTimeout() {
  listener.setTimeout(15 * 60);
  listener.onApplicationEvent(event);
  verify(session, times(1)).setMaxInactiveInterval(15 * 60);
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public void setMaxInactiveInterval(int interval) {
  session.setMaxInactiveInterval(interval);
}

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

@Override
public void setMaxInactiveInterval(int interval) {
  _session.setMaxInactiveInterval(interval);
}

相关文章