Wednesday, May 24, 2017

look at the trap: But you can set a cookie in a servlet/script and then read/modify the cookie in another servlet/script on the same host. You can even read or modify a cookie set on a server running on one port on the same hostname/domain from a server running on another port at the same hostname/domain - so you can have Tomcat running on two different ports on the same server and exchange cookies between the two.

Note that you're calling setDomain incorrectly in the first example - this field of the cookie takes a domain name and not a full URL. So the call should look like this:
cookie.setDomain("localhost");
As the other answer notes, some browsers ignore cookies for localhost, so you may want to not set this field of the cookie at all - this has the effect of setting a cookie that will only be returned to the same host that set it (which most of the time is what you want).



No comments:

Portugal Ukraine Russia (mercenaires killed)

  https://sicnoticias.pt/especiais/guerra-russia-ucrania/2025-04-03-video-russia-diz-ter-abatido-mercenarios-portugueses-na-ucrania-755f2fec