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:

Marques Mendes eleições 2026 corruption cases part 16 ( Ângelo Correia 1)

 https://www.publico.pt/2012/12/03/jornal/angelo-correia-e-marques-mendes-surpreendidos-por-terem-sido-fundadores-25688684