1

I am adding cookies on the client side using JavaScript but they never get sent to the server. The cookies are found in chrome developer tools but the HTTP column is not ticked (I am not sure what that means). enter image description here

I am running Tomcat Server on local host with HTTP only (no HTTPS) and trying to read these cookies from a servlet, but they never make it to the server, nor when I refresh the page neither when I send an ajax request.

I understand that the path needs to be set to / and I do that. In Google chrome cookies persist as expected and I can find them when I close the tab and reopen it. I tried incognito mode as well as normal mode but the results are the same when it comes to the server side. What I am doing wrong???

Alexander
  • 335
  • 1
  • 4
  • 12
  • 1
    First, can you be sure that they are not sent to the server? In Chrome dev tools click the request and then look under "Request Cookies". – johnnyaug Sep 03 '16 at 21:17
  • Good point! +1. They actually show in the cookies tab as well as the Request header. I am trying to retrieve all cookies in the server like this `Cookie[] cookies = request.getCookies();` but this doesn't seem to retrieve them. – Alexander Sep 03 '16 at 22:02
  • Just a note: The HTTP column means that cookies has HTTP Only set which just means the JavaScript in the page can't read the cookie. So it's not relevant to why you're not seeing the cookies server side - just thought I'd through out that nugget of info – winhowes Sep 03 '16 at 22:50
  • @johnnyaug I was actually able to retrieve the cookies as a string from the header. I have asked a new question related to this one. Please have a look if you wish [here](http://stackoverflow.com/questions/39334581/request-getcookies-is-always-null) – Alexander Sep 05 '16 at 16:52

0 Answers0