您的位置:首页 > 理论基础 > 计算机网络

HttpSession 存储验证码失败

2015-09-18 10:55 615 查看
try {
RandomValidateCode randomValidateCode = new RandomValidateCode();
String randomString = randomValidateCode.getRandcode(req, resp);//输出图片方法

// Cannot create a session after the response has been committed
HttpSession session = req.getSession();
session.setAttribute(RandomValidateCode.RANDOMCODEKEY, randomString);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}


如上生成并且存储验证码的代码,在登录页面 url 不输工程名的时候(如 http://127.0.0.1:7878/),会报异常 Cannot create a session after the response has been committed

因此需要把 session.setAttribute(RandomValidateCode.RANDOMCODEKEY, randomString); 在 response 写成验证码图片前执行
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: