首页 > 编程知识 正文

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

时间:2023-05-05 02:06:34 阅读:263518 作者:162

【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:/"; }

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。