app.use(session({
resave: true,
saveUninitialized: true,
secret: 'yunBaby',
cookie: {
maxAge: 1000 * 60 * 30
}
}));
......
router.get('/', function (req, res, next) {
console.log(req.sessionID);
console.log(req.session.name);
if (req.session.name != null) {
res.render('index', {title: req.session.name});
}else{
res.render('index', {title: '测试'});
}
}).post('/', function (req, res) {
........
if (user != null && user != "" && !pswd != null && pswd != "") {
res.render('login', {title: "登录成功!"});
req.session.name = user;
console.log(req.sessionID);
console.log(req.session.name);
} else {
res.render('login', {title: "用户名和密码不能为空!"});
}
});
为啥get那里的session就是没有name,提交post之后session是成功设置了name,但是每次刷新时,get到的session的name都是 undefined . 而且输出的sessionID是一样的。