利用 redis 簡單的防止頁面重複提交

進入提交頁面的方法:

        String uuid=UUID.randomUUID().toString();
        
        LOG.debug("提交生成令牌" + uuid);
        map.addAttribute("serverToken", uuid);
        store.put(uuid, uuid);//已封裝的 redis 的存儲方法

頁面加隱藏域:

                      <input type="hidden" name="clinetToken" id="clinetToken" value="${serverToken}"/>

 

        if(!store.remove(clinetToken)){//防止重複提交代碼:clinetToken在上一步存入redis 如果redis remove token成功返回1 不是重複提交 失敗返回0 重複提交 
            return "/auth/mobile/loginAfter";
        }

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章