本周我作的一个功能解绑当前用户的功能的cookie清除不干净,致使用户没法正常退出‘ html
清除cookie代码 java
String path="/"; String domain=request.getServerName(); domain = Common.handleServerName(domain); Cookie[] cookies=request.getCookies(); for (Cookie cookie : cookies) { path=StringUtil.isBlank(cookie.getPath())?path:cookie.getPath(); domain=StringUtil.isBlank(cookie.getDomain())?domain:cookie.getDomain(); logger.info(cookie.getName()+"--cookie被清除,路径为:"+path+",域名为:"+domain+",value:"+cookie.getValue()); response=CookieUtil.clearCookie(request, response, cookie.getName(),domain,path); }
/** * 清除cookie * */ public static HttpServletResponse clearCookie(HttpServletRequest request,HttpServletResponse response,String name,String domain,String path){ Cookie cookie=new Cookie(name,null); cookie.setMaxAge(0); cookie.setPath(path); cookie.setDomain(domain); response.addCookie(cookie); return response; }
可是老是有一个cookie怎么也清不掉,并且保存cookie的时候也没见到过。 cookie
后边发现,原来是保存在下边的一段cookie,原来是这里的cookie问题 dom
<meta http-equiv="Content-Type"content="text/html; charset=utf-8" /> | |
<meta http-equiv=Set-Cookie | |
content='ddlibCookieName=102433.407238.%E8%8A%9C%E6%B9%96%E5%B8%82%E5%9B%BE%E4%B9%A6%E9%A6%86.9489fa1fb443e34a.261.5.13487; expires=Tue,1 Aug 2023 10:31:24 GMT; path=/;domain=whstsg.ddlib.com' / ui |
问题迎刃而解。
spa