2013-07-09 30 views
1

使用PlayFramework(使用Java),我想記錄所有Cookie名稱Play可以讀取的列表。如何在Play中列出Cookie

我試着打電話給request().cookies()但它不是一個List,它是一個對象,並且在這個對象中沒有List。

我可以打電話給request().cookie(String name);,但這期望我知道cookie的名字,我不知道。

那我該怎麼辦?

感謝您的幫助! :)

回答

1

這是我剛剛作出了一個解決方案,我不知道這是否是最好的,但它的工作原理:

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 ! 
} 
相關問題