Why does cookie.getMaxAge() always return -1 (regardless of real expiry)?

Hitoshi Gosen

By default, the maxAge is set to a negative number.

You should set the maximum age with setMaxAge(int seconds) with a positive number to set your own expiry right after creating the cookie. Use getMaxAge() right after setting the expiry, because once the cookie itself is set to the client browser, the getMaxAge() doesn't perform like the way you are intending.