简体   繁体   中英

How to list cookies in Play

Using PlayFramework (in Java), I'd like to log the list of all cookies name Play can read.

I tried to call request().cookies() but it's not a List, it's an object, and there is no List in this object.

I can call request().cookie(String name); but this expect that I know the cookie's name, which I don't.

How can I do then ?

Here's a solution I just made, I don't know if it's the best, but it works :

for (String cookieStr : request.headers().get("Cookie")) {
    String name = cookieStr.substring(0, cookieStr.indexOf("="));

    Logger.info("Name of the cookie : " + name);

    Cookie cookie = request.cookie(name); // Get the instance of the 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