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