码迷,mamicode.com
首页 > Web开发 > 详细

HttpSession 存储验证码失败

时间:2015-09-18 11:50:52      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

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 写成验证码图片前执行

HttpSession 存储验证码失败

标签:

原文地址:http://www.cnblogs.com/zhiqsyr/p/4818594.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!