Play 2.0 框架 - POST 参数 [英] Play 2.0 framework - POST parameters

查看:24
本文介绍了Play 2.0 框架 - POST 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将参数 POST 到 Action,并在路由中写入:

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

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

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

我有一个动作

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

我的表格是

<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>

它不起作用

对于请求 'POST/login' [Missing parameter: name]

我做错了什么?

推荐答案

只需将路由改为如下:

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

通过不在路由路径中包含动态名称(:name 和 :password),假设变量来自请求(即:您的 html 输入)

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)

您收到的错误表明名称和密码未出现在 url 路径中...这是正确的,因为您在路由中指定的路径表明该路径应如下所示:

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

/login/myname/mypassword

请查看http://www.playframework.org/documentation/2.0.1/JavaRouting 并查看名为调用操作生成器方法"的部分

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

这篇关于Play 2.0 框架 - POST 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆