Cookie getMaxAge

后端 未结 4 2435
南方客
南方客 2021-02-20 01:28

I can\'t retrieve cookie maxage it always returns -1

Creating cookie:

Cookie securityCookie = new Cookie(\"sec\", \"somevalue\");
securityCookie.setMaxAg         


        
4条回答
  •  走了就别回头了
    2021-02-20 02:00

    When a browser sends a cookie back to the origin server, it doesn't include any age. So it is logical that your "retrieve" code above does not receive a max age: it is not included in the request.

    When the cookie is received from the server, the browser uses the max age parameter to determine how long the cookie should be kept; the age is never communicated back to the server, an expired cookie is simply discarded. When processing a request, if you want to renew the age of the cookie, reinclude the cookie in the response.

    Also see the section "Sending Cookies to the Origin Server" in the RFC.

提交回复
热议问题