[英].withSession() not working in Play 2.0
我正在嘗試在Play框架中創建一個新會話,但似乎沒有成功。
得到OpenID結果之后,我想將它們連同剛剛獲得的OpenID信息一起重定向回索引(現在無論如何)。
Redirect(routes.Application.index).withSession(
"id" -> info.id,
"email" -> info.attributes.get("email").getOrElse("unknown@unknown.com"),
"timestamp" -> (System.currentTimeMillis() / 1000L).toString)
這將調用以下函數:
def index = Action { implicit request ⇒
Ok(html.index(request))
}
但是,根據Eclipse,隱式請求具有空cookie和空會話。 這里發生了什么?
如果有幫助,則這是OpenID信息的全部功能:
def openIDCallback = Action { implicit request ⇒
AsyncResult(
OpenID.verifiedId.extend(_.value match {
case Redeemed(info) ⇒ {
Redirect(routes.Application.index).withSession(
"id" -> info.id,
"email" -> info.attributes.get("email").getOrElse("unknown@unknown.com"),
"timestamp" -> (System.currentTimeMillis() / 1000L).toString)
}
case Thrown(t) ⇒ {
// Here you should look at the error, and give feedback to the user
Redirect(routes.Application.index)
}
}))
}
因此,顯然,Eclipse調試器沒有意識到某些值是惰性的。 它只是說它們為空。 這意味着,即使沒有立即調用,Session 看起來也為空。
真正的問題是,在應該使用Session的那部分代碼中,我使用的是request.cookies.get()而不是request.session.get()。 盡管會話是一個cookie,但它是一個具有自己的特殊val的命名cookie。 因此,我的代碼由於不同的原因而闖入了另一個地方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.