81,092
社区成员
发帖
与我相关
我的任务
分享
public class User implements Serializable {
@NotEmpty(message = "{NotEmpty.username}")
@Pattern(regexp="[0-9]{11}", message = "{Pattern.username}")
private String username;
@NotEmpty(message = "{NotEmpty.password}")
@Pattern(regexp="[0-9a-zA-Z_]{6,30}", message = "{Pattern.password}")
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
@RequestMapping(value = "/jsonsource", method = RequestMethod.POST, consumes = "application/json")
public @ResponseBody
User jsonSource(@RequestBody User user) {
return user;
}
var data={
username : username,
password : password
};
$.ajax({
url : '${pageContext.request.contextPath}/jsonsource.html',
data:JSON.stringify(data),
type : 'post',
dataType : 'json',
contentType: "application/json; charset=utf-8",
success : function(data) {
if (data == "success") {
alert(data);
} else {
alert(“失败”);
}
},
error : function(data) {
alert("网络连接异常,请刷新页面或稍后重试!");
}
});