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

Working with controllers and routes

Play applications use controllers to handle HTTP requests and responses. Play controllers are composed of actions that have specific functionality. Play applications use a router to map HTTP requests to controller actions.

How to do it...

To create a new page, which prints out "Hello World" for a Play Java project, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled:
        $ activator "~run"
    
  2. Edit foo_java/app/controllers/Application.java by adding the following action:
        public static Result hello() {
          return ok("Hello World");
        }
  3. Edit foo_java/conf/routes by adding the following line:
        GET    /hello    controllers.Application.hello()
  4. View your new hello page using a web browser:
    http://localhost:9000/hello ...

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