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 XML and text files

Using View templates, we are also able to respond to HTTP requests in other content types such as text files and XML data formats. Play Framework has native handlers for XML and text file content type responses.

How to do it...

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled:
        $ activator "~run"
    
  2. Create the text-based view template file products.scala.txt in app/views/ and add the following content:
        @(productMap: Map[Integer, String])
        @for((id, name) <- productMap) {
          The Product '@name' has an ID of @id
        }
  3. Create the XML-based view template file products.scala.xml in app/views/ and add the following content:
     @(productMap: Map[Integer, String]) <products> @for((id, ...

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