我如何检索通过Java Play中的帖子传递的数据 [英] how do i retrieve data passed thru post in java play

查看:73
本文介绍了我如何检索通过Java Play中的帖子传递的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,在其中我需要检索在POST中发送的数据:

this is my code where i need to retrieve data sent in POST:

@play.db.jpa.Transactional
public static Result registered(String fullname, String email, String password, String username) {
    if(fullname.isEmpty()){
        return badRequest("<p>fehlerhafte eingabe!</p>").as("text/html");
    } else {
    User user = new User();
        user.fullname = fullname;
        user.email = email;
        user.password = password;
        user.username = username;
        user.save();

    }

    String success = "Successful registered!";
    return ok(register.render(success));

}

这是我的用户类:

public class User extends Model {
private static final long serialVersionUID = 1L;
public String fullname;
@Email
public String email;
@Required(message="Username erforderlich!")
public String username;
@Transient @Required
public String password;

public User(){}

public User(String username, String password, String fullname, String email) {
    this.username = username;
    this.password = password;
    this.email = email;
    this.fullname = fullname;
    }

这是我的html:

    <form method="post" action="@routes.Application.registered()">
            <p id="login_panel">@success</p>
            fullname: <input type="text" name="fullname" id="fullname" value=""/>
            email: <input type="text" name="email" id="email" value=""/>
            username: <input type="text" name="username" id="username" value=""/>
            password: <input type="password" name="password" id="password" value=""/>
            <button type="submit">Register</button>
   </form>

这是我的路线:

POST     /registered                controllers.Application.registered()   

什么是WSRequest?这可以为我的问题提供线索吗?

What is WSRequest? can this be the clue for my problem?

我非常感谢您的帮助!谢谢,谢谢

i appreciate any help! thanks thanks

推荐答案

您需要检查控制器类代码.您应该在调用的控制器方法中将所有字段名称都作为参数.然后,您可以在应用程序中使用这些文件.

You need to check the controller class code. You should have all field names as parameter in the called controller method. Then you can use these filed in your application.

这篇关于我如何检索通过Java Play中的帖子传递的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆