java手机验证码5分钟有效,利用session


 final HttpSession httpSession=request.getSession();
       final HttpSession httpSession=request.getSession();
    httpSession.setAttribute(Constants.YXCODE1, code1);
        try {
           
            //TimerTask实现5分钟后从session中删除checkCode
            final Timer timer=new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                   String yxcode1 =  (String) httpSession.getAttribute(Constants.YXCODE1);
          if(StringUtils.isNotEmpty(yxcode1)){
              //确保清除不出错
            httpSession.removeAttribute(Constants.YXCODE1);
          }
                    timer.cancel();
                }
            },5*60*1000);
        } catch (Exception e) {
            e.printStackTrace();
        }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM