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 reverse routing and redirects

One of the more essential tasks for a web application is to be able to redirect HTTP requests, and redirecting HTTP with Play Framework is quite straightforward. This recipe shows how developers can use reverse routing to refer to defined routes.

How to do it…

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled.
  2. Edit foo_java/app/controllers/Application.java by adding the following action:
        public static Result helloRedirect() {
          return redirect(controllers.routes.Application.echo("HelloWorldv2"));
        }
  3. Edit foo_java/conf/routes by adding the following line:
        GET    /v2/hello    controllers.Application.helloRedirect()
  4. View your new echo page using a web browser:
    http://localhost:9000/v2/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