我有一个非常简单的注册表格。我很难理解为什么我的密码字段拒绝值。也许我没有正确设置我的用户bean?我有两个密码字段,一个是用户输入的内容,encryptedPassword使用" org.springframework.security.crypto.password.PasswordEncoder; "加密密码
我正在使用Spring-MVC 4.x,Hibernate 5.x
register.jsp
<sf:form id="registerForm" method="POST" action="${pageContext.request.contextPath}/register/user" commandName="user">
...
<label for="password">Password: </label>
<sf:input type="text" id="password" name="password" path="password"/>
<sf:errors path="password" cssClass="password"></sf:errors>
<label for="confirmPassword">Confirm Password: </label>
<input type="text" id="confirmPassword" name="confirmPassword"/>
<span class="confirmCheck"></span>
....
<input type="submit" value="Submit">
</sf:form>
用户
@Entity
@Table(name="users")
@Component
public class User {
@Transient
@Autowired
private PasswordEncoder passwordEncoder;
@Id
@Column(name = "username")
private String username;
@ValidEmail
private String email;
@Transient
@NotBlank
private String password;
@Column(name="password")
@NotBlank
private String encryptedPassword;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
this.setEncryptedPassword(password);
}
public String getEncryptedPassword() {
return encryptedPassword;
}
public void setEncryptedPassword(String encryptedPassword) {
this.encryptedPassword = (String) passwordEncoder.encode(encryptedPassword).toString();
}
....getter ans setters
}
这是我的实际错误消息
[Field error in object 'user' on field 'password': rejected value [12345678]; codes [methodInvocation.user.password,methodInvocation.password,methodInvocation.java.lang.String,methodInvocation]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.password,password]; arguments []; default message [password]]; default message [Property 'password' threw exception; nested exception is java.lang.NullPointerException], Field error in object 'user' on field 'encryptedPassword': rejected value [null]; codes [NotBlank.user.encryptedPassword,NotBlank.encryptedPassword,NotBlank.java.lang.String,NotBlank]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.encryptedPassword,encryptedPassword]; arguments []; default message [encryptedPassword]]; default message [may not be empty]]