简体   繁体   中英

How to read cookies in Scala play?

I'm adding Cookie like so:

              Redirect(routes.UserPage.form(usersignin.email)).withCookies(Cookie("guid", md5hash1cookie))

How could i read it?

If i use:

println(Http.Request.current().cookies.get("guid"));

and i get error:

not found: value Http

UPD 1:

Correct way to use is 
  def form(msg: String = "") = Action {
    request => {
      //  guid = guId.toString();
        println(request.cookies.get("guid"));
...

  }
}

How to get value out of coockie? println(request.cookies.get("guid")); returns Some(Cookie(guid,7a3bdea2ba59a196c02fb7bdbcdb4e26,None,/,None,false,false))

and i need just 7a3bdea2ba59a196c02fb7bdbcdb4e26 returned as string.

Solution:

for(gu <- request.cookies.get("guid")){
          println(gu.value);
      }

您没有在Scala Play API中包含请求的共享状态,相反,您将必须使用Action { request =>方法来定义操作,在请求上,然后您可以通过request.cookies访问cookie。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM