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

查看:87
本文介绍了Play 2.0框架-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]

我在做什么错了?

推荐答案

只需将路由更改为以下内容:

Simply change the route to the following:

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天全站免登陆