【Cookie】清除Cookie,退出登录功能实现

【Cookie】清除Cookie,退出登录功能实现

清理Cookie

  • 新建一个同名的Cookie,value为null,替换掉原有的Cookie

SpringBoot代码展示

@GetMapping("/index")
    public String go_index(
            HttpServletRequest request,
            HttpServletResponse response){
        request.getSession().removeAttribute("user");
        Cookie cookie = new Cookie("token",null);
        cookie.setMaxAge(0);//设置存活时间,“0”即马上消失
        cookie.setPath("/");
        response.addCookie(cookie);
        return "redirect:/";
    }
发布了28 篇原创文章 · 获赞 4 · 访问量 1327

猜你喜欢

转载自blog.csdn.net/weixin_44100826/article/details/103255960
今日推荐