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 the session

For this recipe, we will explore how Play applications handle a session state. This sounds counterintuitive, as Play claims to be a stateless and lightweight web framework. However, as sessions and session states have become major components for web applications, Play implements sessions as cookies and therefore, are actually stored on the client side or the user browser.

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 modifySession() { final String sessionVar = "user_pref"; final String userPref = session(sessionVar); if (userPref == null) { session(sessionVar, ...

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