Java JAX-RS cookie删除失败

Java JAX-RS cookie删除失败,java,cookies,jersey,jax-rs,Java,Cookies,Jersey,Jax Rs,我无法从请求中删除一些cookie(2),我不知道为什么 我试过这样做: 将到期时间设置为0,值设置为空,将安全标志设置为false 将过期设置为0,值设置为null,将安全标志设置为true 以下内容对我有用,但您需要知道cookies的名称并逐个删除它们: @GET @Path("clear-cookie") @Produces(MediaType.TEXT_PLAIN) public Response clear-cookie(@CookieParam("COOKIE_NAME") jav

我无法从请求中删除一些cookie(2),我不知道为什么

我试过这样做:

将到期时间设置为0,值设置为空,将安全标志设置为false 将过期设置为0,值设置为null,将安全标志设置为true
以下内容对我有用,但您需要知道cookies的名称并逐个删除它们:

@GET
@Path("clear-cookie")
@Produces(MediaType.TEXT_PLAIN)
public Response clear-cookie(@CookieParam("COOKIE_NAME") javax.ws.rs.core.Cookie cookie) {
    if (cookie != null) {
    NewCookie newCookie = new NewCookie(cookie, null, 0, false);
    return Response.ok("OK").cookie(newCookie).build();
    }
    return Response.ok("OK - No session").build();
}

我已经通过描述所有公共参数的通用方法解决了这个问题。至少三个参数必须相等:名称(=“name”)、路径(“/”)和域(=null):

并按set的常用方式使用:

NewCookie domainNewCookie = RsCookieHelper.createDomainCookie(token, 60);
Response res = Response.status(Response.Status.OK).cookie(domainNewCookie).build();
删除:

NewCookie domainNewCookie = RsCookieHelper.createDomainCookie("", 0);
Response res = Response.status(Response.Status.OK).cookie(domainNewCookie).build();

可能重复的坦克很多,我尝试与该代码,它的作品很好!将最大年龄设置为0,过期日期设置为现在(new date())。它不会删除现有cookie。看这里:
public static NewCookie createDomainCookie(String value, int maxAgeInMinutes) {
    ZonedDateTime time = ZonedDateTime.now().plusMinutes(maxAgeInMinutes);
    Date expiry = time.toInstant().toEpochMilli();
    NewCookie newCookie = new NewCookie("name", value, "/", null, Cookie.DEFAULT_VERSION,null, maxAgeInMinutes*60, expiry, false, false);
    return newCookie;
}
NewCookie domainNewCookie = RsCookieHelper.createDomainCookie(token, 60);
Response res = Response.status(Response.Status.OK).cookie(domainNewCookie).build();
NewCookie domainNewCookie = RsCookieHelper.createDomainCookie("", 0);
Response res = Response.status(Response.Status.OK).cookie(domainNewCookie).build();