后端代码,使用了工具类返回流返回map对象
UserService us =(UserService) ServiceFactory.getService(new UserServiceImpl());
try{
User user =us.login(loginAct,loginPwd,ip);
request.getSession().setAttribute("user",user);
//程序到此处说明,业务层Controller没有抛出异常。向页面返回登陆成功信息
PrintJson.printJsonFlag(response,true);
前端代码:
$.ajax({
url: “settings/user/login.do”,
data:{
“loginAct”:loginAct,
“loginPwd”:loginPwd
},
type:“post”,
datatype:“json”,
success:function (data) {
/* data
{“success”:true/false,“msg”:“哪错了”}*/
//登陆成功跳转到工作台
***var data1 = JSON.parse(data); ***//此处需将map对象转为JSON对象
if(data1.success){
window.location.href=“workbench/index.html”;
}else{
//登陆失败
$("#msg").html(data1.msg);
}
https://blog.youkuaiyun.com/weixin_34067049/article/details/92206209