尝试使用Spring登录

时间:2013-02-11 13:01:47

标签: java html spring authentication login

所以我们正在为我们的项目登录。我们遇到的问题是我们只在参数中得到null而不是我们输入的实际值。有谁知道为什么?

控制器代码:

@RequestMapping(value = "/user/login",method = RequestMethod.POST)
public String logIn(@ModelAttribute("user") User user) {

 //Random code here

 return "redirect:/general/index.html";

}

查看:

<form:form id="header_login_form" method="POST"  ModelAttribute="user" action="/ProjectTeamF-1.0/user/login.html">
    <input path="username"class="input" placeholder="Email" />
    <input path="password" class="input" placeholder="Password" />
    <label class="checkbox">
    <input type="checkbox"> Aangemeld blijven</label>
    <button type="submit" class="btn">Aanmelden</button>
</form:form>

1 个答案:

答案 0 :(得分:0)

您需要使用标记<form:input>而不是<input>,以便Spring绑定user ModelAttribute。并将ModelAttribute替换为commandName

<form:form id="header_login_form" method="POST"  commandName="user" action="/ProjectTeamF-1.0/user/login.html">
    <form:input path="username"class="input" placeholder="Email" />
    <form:input path="password" class="input" placeholder="Password" />
    <label class="checkbox">
    <input type="checkbox"> Aangemeld blijven</label>
    <button type="submit" class="btn">Aanmelden</button>
</form:form>