52,797
社区成员
发帖
与我相关
我的任务
分享
function login(){
var userId = document.getElementById("UserName").value;
var password = document.getElementById("PassWord").value;
if(userId == null || userId == ""){
alert("用户名不可为空!");
return;
}
if(password == null || password == ""){
alert("密码不可为空!");
return;
}
var strUrl = "dologin.action";
var params={"UserName":userId,"PassWord":password};
debugger;
$.ajax({
type : 'post',
url : strUrl,
data : {
UserName : userId,
PassWord:password
},
dataType: "json",
async : true,
success : function(data) {
debugger;
if(data.ReturnCode=="0"){
window.location.href="goToHome.action";
}
else{
alert("登录失败,用户名或者密码错误!");
}
}
});
}
@RequestMapping(value="/dologin")
@ResponseBody
public String dologin(HttpServletResponse response){
String username = request.getParameter(ITag.UserName);
String password = request.getParameter(ITag.PassWord);
Map<String,String> map = new HashMap<String, String>();
User u =new User();
u.setUserName(username);
u.setUserPassword(password);
u = this.userService.login(u);
if(u!=null){
request.getSession().setAttribute("user", u);
map.put(ITag.ReturnCode, "0");
}else{
// request.setAttribute(ITag.ErrorMessage, "您输入的用户名或密码不正确!");
map.put(ITag.ReturnCode, "-1");
map.put(ITag.ErrorMessage, "您输入的用户名或密码不正确!");
}
String jsonResponse = JSON.toJSONString(map);
System.out.println(username+":"+password);
System.out.println(jsonResponse);
return jsonResponse;
}