Java – how to get form data in play framework

Before asking this question, I found this neat post (but it can't solve my problem):

I'm trying to use the play framework as the back end to update the record of Ajax calls

Here are some data about my request:

Request URL:http://172.20.12.50:9000/updateName
Request Method:PUT

Form Data
name=&value=Testttt&pk=367

This is how I tried to test it on the server side:

Logger.info("PK IS " + request().getQueryString("pk"));

This is what I got in my log:

[info] application - PK IS null

How do I get these parameters from formdata? I received data about my request from firebug

Solution

The post data has a request() Available in the controller of body()

On the body, you can call Asformurlencoded() to retrieve the map of the data You will find more information in the documentation

For more complex use cases, you can use the form API to define data constraints and validation, and bind the data directly to specific classes

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>