Javacookies - opensas/Play20Es GitHub Wiki
Esta página todavía no ha sido traducida al castellano. Puedes ayudarnos con la tarea simplemente presionando el botón
Edit Page. Para más información puedes leer esta guía para el traductor. Aquí puedes ver cuánto nos falta para terminar la traducción.
You can retrieve the request’s cookies using the cookies() method of a Http.Request object:
public class Application extends Controller {
public static Result index() {
Http.Cookie cookie = request().cookies().get("foo");
if (cookie.value().equals("bar")) {
// ...
}
}
}The get(String name) method returns the cookie or null if there was no such cookie. See the API documentation of the Http.Cookie class to know what information is available on cookies.
Setting cookies and discarding them is performed through the setCookie and discardCookies methods of the Http.Response object:
public class Application extends Controller {
public static Result index() {
// Set cookies
response().setCookie("bar", "baz");
response().setCookie("bar", "baz", 3600);
// Discard cookies
response().discardCookies("foo", "bar");
// ...
}
}See the various overloaded versions of the setCookie method in the API documentation to know all the possible combinations of parameters.