问题
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);
}
However, I'm getting this error in Eclipse:
"The method form() is undefined for the type Form
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?
Thanks!
回答1:
You imported the wrong Form
class. You need to import play.data.Form
as shown in the Javadoc.
The class play.api.data.Form
is part of the Scala version of Play as shown in the Scaladoc.
来源:https://stackoverflow.com/questions/21072889/handling-a-post-request-in-play-framework-2-2-x-with-java