Play 2.0 framework - POST parameters

后端 未结 3 940
粉色の甜心
粉色の甜心 2021-01-18 15:09

I\'m trying to POST parameters to Action, and wrote in the routes:

# Home page
GET    /                         controllers.Application.index()

POST   /logi         


        
相关标签:
3条回答
  • 2021-01-18 15:31

    Though an old post, but if anyone new comes to the question. We should not add parameters, when you are using post, also if you did use parameters, it would be GET /login/:name/:password controllers.Application.login(name: String, password: String)

    For post, don't add parameters and bind it to a case class inside the controllers and access the variables.

    0 讨论(0)
  • 2021-01-18 15:32

    your route should not include dynamic parts (name, password) since the data is in the body and not the url

    0 讨论(0)
  • 2021-01-18 15:51

    Simply change the route to the following:

    POST   /login    controllers.Application.login(name, password)
    

    By NOT including the dynamic names (:name and :password) in the routing path, the assumption is that the variables come from the request (IE: your html inputs)

    The error you are getting indicates that name and password do not appear in the url path... which is correct because the path you specified in your routes indicates the path should look something like this:

    /login/myname/mypassword

    Please check http://www.playframework.org/documentation/2.0.1/JavaRouting and look at the section called "Call to action generator method"

    0 讨论(0)
提交回复
热议问题