How to get post data in play framework

4 Flares Twitter 0 Facebook 2 Google+ 2 LinkedIn 0 Filament.io 4 Flares ×

Play framework provides HTTP Routing capabilities and you can configure the routing in conf/route file. Probably you already know how to configure the GET requests. Let us look at handling POST data in play framework.

Here is a sample configuration defined in the conf/routes file

In this sample, the saveComment method doesn’t take any parameters and the protocol is POST. So there has to be some way in the controller to retrieve the post data. Of course there is and is very easy. You can access the post data as show below.

This map contains the post values as key value pairs. Let us consider that the comment was passed with the key ‘comment’. We can retrieve the value as follows

  • Rupanjan Baidya

    How to bind a xml in object through Post?