spark.Request.session()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(191)

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

Request.session介绍

[英]Returns the current session associated with this request, or if the request does not have a session, creates one.
[中]返回与此请求关联的当前会话,如果请求没有会话,则创建一个会话。

代码示例

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

@Override
public Session session(boolean create) {
  return delegate.session(create);
}

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

@Override
public Session session() {
  return delegate.session();
}

代码示例来源:origin: bwssytems/ha-bridge

public void removeAuthenticatedUser(Request request) {
  request.session().removeAttribute(USER_SESSION_ID);
  
}

代码示例来源:origin: bwssytems/ha-bridge

public void addAuthenticatedUser(Request request, User u) {
  request.session().attribute(USER_SESSION_ID, u);
  
}

代码示例来源:origin: bwssytems/ha-bridge

public User getAuthenticatedUser(Request request) {
  User theUser = request.session().attribute(USER_SESSION_ID);
  if(theUser == null) {
    String authHeader = request.headers("Authorization");

代码示例来源:origin: cinchapi/concourse

@Override
public Session session() {
  return delegate.session();
}

代码示例来源:origin: cinchapi/concourse

@Override
public Session session(boolean create) {
  return delegate.session(create);
}

代码示例来源:origin: com.sparkjava/spark-core

@Override
public Session session() {
  return delegate.session();
}

代码示例来源:origin: com.sparkjava/spark-core

@Override
public Session session(boolean create) {
  return delegate.session(create);
}

代码示例来源:origin: tipsy/spark-basic-structure

public static String removeSessionAttrLoginRedirect(Request request) {
  String loginRedirect = request.session().attribute("loginRedirect");
  request.session().removeAttribute("loginRedirect");
  return loginRedirect;
}

代码示例来源:origin: tipsy/spark-basic-structure

public static boolean removeSessionAttrLoggedOut(Request request) {
  Object loggedOut = request.session().attribute("loggedOut");
  request.session().removeAttribute("loggedOut");
  return loggedOut != null;
}

代码示例来源:origin: tipsy/spark-basic-structure

public static String removeSessionAttrLoginRedirect(Request request) {
  String loginRedirect = request.session().attribute("loginRedirect");
  request.session().removeAttribute("loginRedirect");
  return loginRedirect;
}

代码示例来源:origin: tipsy/spark-basic-structure

public static boolean removeSessionAttrLoggedOut(Request request) {
  Object loggedOut = request.session().attribute("loggedOut");
  request.session().removeAttribute("loggedOut");
  return loggedOut != null;
}

代码示例来源:origin: eh3rrera/minitwit

private User getAuthenticatedUser(Request request) {
    return request.session().attribute(USER_SESSION_ID);
  }
}

代码示例来源:origin: tipsy/spark-basic-structure

public static String getSessionLocale(Request request) {
  return request.session().attribute("locale");
}

代码示例来源:origin: tipsy/spark-basic-structure

public static String getSessionCurrentUser(Request request) {
  return request.session().attribute("currentUser");
}

代码示例来源:origin: beryx/text-io

protected static String getId(Request request) {
  Session session = request.session();
  String id = session.id();
  String uuid = request.headers("uuid");
  if(uuid != null) {
    id += "-" + uuid;
  }
  logger.trace("id: {}", id);
  return id;
}

代码示例来源:origin: tipsy/spark-basic-structure

public static void ensureUserIsLoggedIn(Request request, Response response) {
  if (request.session().attribute("currentUser") == null) {
    request.session().attribute("loginRedirect", request.pathInfo());
    response.redirect(Path.Web.LOGIN);
  }
};

代码示例来源:origin: tipsy/spark-basic-structure

public static void ensureUserIsLoggedIn(Request request, Response response) {
  if (request.session().attribute("currentUser") == null) {
    request.session().attribute("loginRedirect", request.pathInfo());
    response.redirect(Path.Web.LOGIN);
  }
};

代码示例来源:origin: vanillasource/jaywire

public void addRoutes() {
   Spark.before((request, response) -> {
     getServletRequestScope().setStorage(request.raw());
     getHttpSessionScope().setStorage(request.session(true).raw());
   });
   Spark.after((request, response) -> {
     getServletRequestScope().clearStorage();
      getHttpSessionScope().clearStorage();
   });
  }
}

相关文章