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

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

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

HttpSession.isNew介绍

[英]Returns true if the client does not yet know about the session or if the client chooses not to join the session. For example, if the server used only cookie-based sessions, and the client had disabled the use of cookies, then a session would be new on each request.
[中]如果客户端尚不知道该会话,或者如果客户端选择不加入该会话,则返回true。例如,如果服务器仅使用基于cookie的会话,而客户端已禁用cookie的使用,则每个请求都会有一个新的会话。

代码示例

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

/**
 * @return true if the client does not yet know about the session or if the client chooses not to join the session.
 */
public boolean isNew() {
  return session.isNew();
}

代码示例来源:origin: stackoverflow.com

HttpSession session = request.getSession(false);// don't create if it doesn't exist
if(session != null && !session.isNew()) {
  chain.doFilter(request, response);
} else {
  response.sendRedirect("/login.jsp");
}

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

public boolean isNew() {
  return session.isNew();
}

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

public boolean isNew() {
  return session.isNew();
}

代码示例来源:origin: stackoverflow.com

HttpSession session = request.getSession();
if (session.isNew()) {
  // Freshly created.
} else {
  // Already created.
}

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

@Override
 public void call(HttpServletRequest request, HttpServletResponse response)
   throws IOException {
  HttpSession session = request.getSession();
  response.getWriter().write(Boolean.toString(session.isNew()));
 }
};

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

/**
 * @param id Session ID.
 * @param ses Session.
 */
WebSession(String id, HttpSession ses) {
  assert id != null;
  assert ses != null;
  this.id = id;
  createTime = ses.getCreationTime();
  accessTime = ses.getLastAccessedTime();
  maxInactiveInterval = ses.getMaxInactiveInterval();
  isNew = ses.isNew();
  attrs = new HashMap<>();
  Enumeration<String> names = ses.getAttributeNames();
  while (names.hasMoreElements()) {
    String name = names.nextElement();
    attrs.put(name, ses.getAttribute(name));
  }
}

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

if (session != null) {
  session.isNew();
  return session;

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

@Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    assertThat(wrappedRequest.getSession().isNew()).isTrue();
    assertThat(wrappedRequest.getSession().isNew()).isTrue();
  }
});

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

@Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    assertThat(wrappedRequest.getSession().isNew()).isFalse();
  }
});

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

@Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    assertThat(wrappedRequest.getSession().isNew()).isFalse();
  }
});

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

@Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    HttpSession session = wrappedRequest.getSession();
    session.invalidate();
    try {
      session.isNew();
      fail("Expected Exception");
    }
    catch (IllegalStateException ignored) {
    }
  }
});

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

@Test
public void buildRequestSessionIsNew() throws Exception {
  MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
  assertThat(actualRequest.getSession().isNew(), equalTo(true));
}

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

@Test
public void buildRequestSessionInvalidate() throws Exception {
  String sessionId = "session-id";
  webRequest.setAdditionalHeader("Cookie", "JSESSIONID=" + sessionId);
  MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
  HttpSession sessionToRemove = actualRequest.getSession();
  sessionToRemove.invalidate();
  assertThat(sessions.containsKey(sessionToRemove.getId()), equalTo(false));
  assertSingleSessionCookie("JSESSIONID=" + sessionToRemove.getId()
      + "; Expires=Thu, 01-Jan-1970 00:00:01 GMT; Path=/test; Domain=example.com");
  webRequest.removeAdditionalHeader("Cookie");
  requestBuilder = new HtmlUnitRequestBuilder(sessions, webClient, webRequest);
  actualRequest = requestBuilder.buildRequest(servletContext);
  assertThat(actualRequest.getSession().isNew(), equalTo(true));
  assertThat(sessions.containsKey(sessionToRemove.getId()), equalTo(false));
}

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

@Test
public void buildRequestSessionIsNewFalse() throws Exception {
  String sessionId = "session-id";
  webRequest.setAdditionalHeader("Cookie", "JSESSIONID=" + sessionId);
  MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
  assertThat(actualRequest.getSession().isNew(), equalTo(false));
}

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

@Test    // http@create-session=always
public void configureWhenSessionCreationPolicyAlwaysThenSessionCreatedOnRequest() throws Exception {
  this.spring.register(CreateSessionAlwaysConfig.class).autowire();
  MvcResult mvcResult = this.mockMvc.perform(get("/")).andReturn();
  HttpSession session = mvcResult.getRequest().getSession(false);
  assertThat(session).isNotNull();
  assertThat(session.isNew()).isTrue();
}

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

@Test    // http@create-session=ifRequired
public void configureWhenSessionCreationPolicyIfRequiredThenSessionCreatedWhenRequiredOnRequest() throws Exception {
  this.spring.register(IfRequiredConfig.class).autowire();
  MvcResult mvcResult = this.mockMvc.perform(get("/unsecure")).andReturn();
  HttpSession session = mvcResult.getRequest().getSession(false);
  assertThat(session).isNull();
  mvcResult = this.mockMvc.perform(formLogin()).andReturn();
  session = mvcResult.getRequest().getSession(false);
  assertThat(session).isNotNull();
  assertThat(session.isNew()).isTrue();
}

代码示例来源:origin: stackoverflow.com

HttpSession session = request.getSession();
if (session.isNew()) {
  // Session is freshly created during this request.
} else {
  // Session was already created during a previous request.
}

代码示例来源:origin: stackoverflow.com

HttpSession session = request.getSession();

if (!session.isNew()) {
  session.invalidate();
  session = request.getSession();
}

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

if (s != null && s.isNew()) {
  s.setAttribute(FrameworkConfig.BROADCASTER_FACTORY, config.getBroadcasterFactory());

相关文章