首页 > Web开发 > 详细

HttpSession 存储验证码失败

时间:2015-09-18 11:50:18      阅读:217      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!