The validity period of a Java Web cookie

Source: Internet
Author: User
Tags java web

Validity period in cookies in the Java web

(1) Java Web Background Add cookie

Cookie Emailcook = new Cookie (name2, "Whuang"); Emailcook.setpath ("/"); Response.addcookie (Emailcook);

(2) does not explicitly set the validity period, the validity period is the session, that is, after closing the browser will expire


(3) Set validity period:

Emailcook.setmaxage (10000000); Response.addcookie (Emailcook);

The unit of Setmaxage is: seconds

public void Setmaxage (int expiry)
    • Sets the maximum age of the cookies in seconds.

      A positive value indicates that the cookie would expire after that many seconds has passed. Note that the value was the maximum age when the cookie would expire, not the cookie's current age.

      A negative value means that the cookie was not stored persistently and would be deleted when the Web browser exits. A zero value causes the cookie to be deleted.


      • Parameters:

      • expiry-an integer specifying the maximum age of the cookie in seconds; If negative, means the cookie is not stored; If zero, deletes the cookie


This article is from the "Whuang" blog, make sure to keep this source http://huangkunlun520.blog.51cto.com/2562772/1701945

The validity period of a Java Web cookie

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.