简体   繁体   English

为什么我的JSP不会删除Cookie

[英]Why won't my JSP remove cookie

I want to delete a cookie in my login page, no matter what I do, it just won't go away. 我想在登录页面中删除一个cookie,无论我做什么,它都不会消失。 in chrome developer, it shows the response from the server contains no cookie even though I had add it using response.addCookie() . 在chrome开发人员中,即使我已使用response.addCookie()将其添加,它也显示了来自服务器的响应不包含cookie。

Here's the JSP code that removes the code. 这是删除代码的JSP代码。 It's at the beginning of the page, right after the content-type being set and before any output. 它位于页面的开头,紧随设置的内容类型之后,位于任何输出之前。 this JSP is in the tile view (not sure if it makes any difference). 此JSP在图块视图中(不确定是否有任何区别)。 I also tried moving this code to the containing JSP, but no help either. 我也尝试将这段代码移动到包含JSP的代码中,但也没有帮助。

<%@ page contentType="text/html; charset=UTF-8" %>
<%
// remove cookie.  all the properties (domain, path secure) match those those when   the cookie was being created and set.
Cookie ck = new Cookie(someName,"");
ck.setMaxAge(0);
ck.setValue("");
ck.setPath("/");
ck.setDomain(someDomain);
    ck.setSecure(true);
response.addCookie(ck);
System.out.println("wwwwwww 999991111");
%>

thanks. 谢谢。

Use 采用

cookie.setPath(request.getContextPath());

your code only works if the application is deployed to the root. 仅当应用程序部署到根目录时,您的代码才有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM