使用Java处理Play Framework 2.2.x中的POST请求? [英] Handling a POST request in Play Framework 2.2.x with Java?
问题描述
我开始使用Play 2.2.x,正在尝试处理POST请求,据我了解,我不需要在conf/routes文件中指定参数,而是使用play的DynamicForm类提取查询,如下所示:
I'm getting started with Play 2.2.x, I'm trying to handle a POST requests, it's my understanding that I don't need to specify parameters in the conf/routes file but extract the queries using play's DynamicForm class, as below:
import play.*;
import play.api.data.Form;
import play.data.DynamicForm;
import play.mvc.*;
import views.html.*;
public static Result hello() {
DynamicForm requestData = Form.form().bindFromRequest();
String firstname = requestData.get("firstname");
String lastname = requestData.get("lastname");
return ok("Hello " + firstname + " " + lastname);
}
但是,我在Eclipse中遇到此错误:
However, I'm getting this error in Eclipse:
"The method form() is undefined for the type Form
当我执行"play run"时,我正在得到这个编译器:
And I'm getting this compiler when i execute "play run":
error: cannot find symbol
DynamicForm data = Form.form().bindFromRequest();
此代码有什么问题?此类或方法是否已弃用?
What is wrong with this code? Is this class or method deprecated?
谢谢!
推荐答案
您导入了错误的Form
类.您需要导入play.data.Form
,如 Javadoc 中所示.
You imported the wrong Form
class. You need to import play.data.Form
as shown in the Javadoc.
类play.api.data.Form
是Play的 Scala 版本的一部分,如
The class play.api.data.Form
is part of the Scala version of Play as shown in the Scaladoc.
这篇关于使用Java处理Play Framework 2.2.x中的POST请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!