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 Caso Gémeas Politics ( BACK2WAR Intelligence deliver to Russia several e-mails "Brazilian Twins affair" next step, how much did it "roll under the table" and also on "Santa Casa Case" ? IT WILL HV A PRICE

  https://observador.pt/2024/01/27/comunicacoes-da-presidencia-indicam-envolvimento-direto-de-nuno-rebelo-de-sousa-e-que-marcelo-recebeu-var...