ssm传session到jsp获取不到。因为ajax用的location.href 中间经过了页面跳转,结果收不到了
$.ajax({
type: 'post',
url: '${pageContext.request.contextPath}/toLogin',
data: {'userName': userName, 'password': password, 'entity': entity},
dataType: 'text',
success: function (res) {
if (res == "success") {
layer.msg('登录成功!', {
offset: '15px'
, icon: 1
, time: 1000
});
if (entity=="管理员"){
window.location.href='/adminIndex'
}else if (entity=="学生"){
window.location.href='/studentIndex'
}else if (entity=="教师"){
window.location.href='/teacherIndex'
}
}
@RequestMapping("toLogin")
@ResponseBody
public String toLogin(String userName, String password, String entity,Model model) {
if (entity.equals("管理员")) {
Admin admin = service.checkAdmin(userName);
System.out.println(admin);
if (admin != null && admin.getPassword().equals(password)) {
model.addAttribute("admin",admin);
return "success";
} else {
return "fail";
}
}
public String adminIndex(Model model) {
System.out.println(model.getAttribute("admin"));
return "adminIndex";
}
传递的session是有内容的,接收的null。什么情况呀。。