本文整理匯總了Java中play.mvc.Http.Session方法的典型用法代碼示例。如果您正苦於以下問題:Java Http.Session方法的具體用法?Java Http.Session怎麽用?Java Http.Session使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類play.mvc.Http
的用法示例。
在下文中一共展示了Http.Session方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validate
import play.mvc.Http; //導入方法依賴的package包/類
public String validate() {
User user = UserUtil.authenticate(userDao.findUserByUsername(username), password);
if (user == null) {
return "Invalid username or password";
} else if (!user.isActive()) {
return "User account is currently inactive. An admin will activate your account shortly.";
} else {
Http.Session session = Http.Context.current().session();
session.clear();
session.put("uid", Long.toString(user.getId()));
session.put("user_role", user.getRoles().get(0).getName());
session.put("username", user.getUsername());
// TODO: token based auth and session timeout
}
return null;
}
示例2: isResponseSuccessful
import play.mvc.Http; //導入方法依賴的package包/類
private boolean isResponseSuccessful(Http.Session session, WSResponse wsResponse) {
if (wsResponse.getStatus() >= 400) {
if (wsResponse.getStatus() == 401) {
System.out.println("Invalid TOKEN redirecting to GitHub Auth");
session.remove(TOKEN_KEY);
}
return false;
}
return true;
}
示例3: saveSkuInSession
import play.mvc.Http; //導入方法依賴的package包/類
static void saveSkuInSession(final Http.Session session, final String sku) {
final List<String> skuList = findLastViewedProductsSkuInSession(session);
skuList.remove(sku);
skuList.add(sku);
while (skuList.size() > MAX_CAPACITY) {
skuList.remove(0);
}
try {
session.put(SESSION_KEY, Json.mapper().writeValueAsString(skuList));
LOGGER_SAVER.debug("Saved product with SKU {} to session: {}", sku, skuList);
} catch (JsonProcessingException e) {
LOGGER_SAVER.error("Could not serialize SKU list {} into JSON", skuList, e);
}
}
開發者ID:commercetools,項目名稱:commercetools-sunrise-java-training,代碼行數:15,代碼來源:LastViewedProductUtils.java
示例4: findLastViewedProductsSkuInSession
import play.mvc.Http; //導入方法依賴的package包/類
static List<String> findLastViewedProductsSkuInSession(final Http.Session session) {
final List<String> skuList = new LinkedList<>();
Json.parse(session.getOrDefault(SESSION_KEY, "[]")).elements()
.forEachRemaining(node -> skuList.add(node.asText()));
return skuList;
}
開發者ID:commercetools,項目名稱:commercetools-sunrise-java-training,代碼行數:7,代碼來源:LastViewedProductUtils.java