Handling a POST request in Play Framework 2.2.x with Java?

ⅰ亾dé卋堺 提交于 2019-12-08 12:46:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!