首页 > playframework > 如何在Play Framework 2.2.1中处理表单提交

如何在Play Framework 2.2.1中处理表单提交 (how to handle form submissions in Play Framework 2.2.1)

问题

我使用以下示例来处理Play框架2.2.1中的表单提交。但是,play.data在游戏框架2.2.1中不再存在。所以下面的示例根本不起作用。

在play框架2.2.1中是否有新的处理表单提交?

public static Result formSubmit() {
    DynamicForm requestData = form().bindFromRequest();
    String firstname = requestData.get("firstname");
    String lastname = requestData.get("lastname");
    return ok("Hello " + firstname + " " + lastname);
}

java:10: cannot find symbol
[error] symbol  : class DynamicForm

解决方法

当然它仍然存在,但是前段时间被重构了......检查你的导入应该是:

import play.data.DynamicForm ;

import static play.data.Form.form ;

问题

I used the following sample to handle form submission in Play framework 2.2.1. However, play.data doesnt exist any more in play framework 2.2.1. So the sample below doesn't work at all.

Is there a new to handle form submission in play framework 2.2.1?

public static Result formSubmit() {
    DynamicForm requestData = form().bindFromRequest();
    String firstname = requestData.get("firstname");
    String lastname = requestData.get("lastname");
    return ok("Hello " + firstname + " " + lastname);
}

java:10: cannot find symbol
[error] symbol  : class DynamicForm

解决方法

Of course it exists still, but was refactored some time ago... check your imports that should be:

import play.data.DynamicForm;

import static play.data.Form.form;

相似信息