销毁 Session 和 Cookie

2022-10-28 08:50:43 浏览数 (1)

销毁 Session 和 Cookie

代码语言:javascript复制
private static void resetCookie(HttpServletRequest request, HttpServletResponse response) {
        Cookie userCodeCookie = new Cookie("userCode", null);
        Cookie userNickname = new Cookie("userNickname", null);
        Cookie userTableName = new Cookie("userTableName", null);
        userCodeCookie.setMaxAge(0);
        userNickname.setMaxAge(0);
        userTableName.setMaxAge(0);
        userCodeCookie.setPath("/");
        userNickname.setPath("/");
        userTableName.setPath("/");
        response.addCookie(userCodeCookie);
        response.addCookie(userNickname);
        response.addCookie(userTableName);
        request.getSession().invalidate();
    }

0 人点赞