Play 2.0 Interface - POST Settings

I am trying to set the POST parameters in Action and wrote in the routes:

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

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

and i have action

public static Result login(String name, String password) {
    return ok(name + " "  + password);
}

my form

<form action="/login" method="post">

    <input name="name" type="text" id="name">
    <input name="password" type="password" id="password">
    <input type="submit" value="Login">

</form>

And it does not work

For request 'POST /login' [Missing parameter: name]

What am I doing wrong?

+5
source share
2 answers

Just change the route to the following:

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

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

The error you get indicates that the username and password do not appear in the URL ... which is correct, because the path you specified on your routes indicates that the path should look something like this:

/ Login / MyName / my password

, http://www.playframework.org/documentation/2.0.1/JavaRouting " "

+3

(, ), , URL

+3

All Articles