O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using HTTP cookies

For this recipe, we will explore how Play applications can manipulate HTTP cookies. We will use the curl tool to validate our changes to the HTTP response headers containing the new cookie we added to the response.

How to do it…

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled.
  2. Modify foo_java/app/controllers/Application.scala by adding the following action:
      public static Result modifyCookies() {
            response().setCookie("source", "tw", (60*60));
            return ok("Cookie Modification Example");
         }
  3. Add a new route entry for the newly-added action in foo_java/conf/routes:
      GET   /cookie_example    controllers.Application.modifyCookies
  4. Request our new route and examine the response headers to confirm ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required