Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cookie set by Javascript doesn't show up in HttpServletRequest  RSS feed

 
Scott Shipp
Ranch Hand
Posts: 223
12
Eclipse IDE IntelliJ IDE Java Scala Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any idea why this might be? I've got a banner that displays on the web page and users can close it out by clicking an "X" button in its corner. Once it's closed, we track for that session that it remains closed, so a cookie gets set. I'd like subsequent requests to the server to be aware of this cookie so that the banner code is just not included in subsequent responses. (Sidebar: earlier I was just detecting the cookie after page load and then hiding the banner but it creates a lag where the banner is visible then suddenly pops away, making for poor user experience.)

I expect that even though Javascript set the cookie it would then show up in HttpServletRequest.getCookies() call, but there's actually a lot of cookies visible in Chrome Developer Tools on the client of my page that don't show up in .getCookies(). Any idea what might be going on? Does the HttpServletResponse.addCookie need called at some point first for the cookie to be passed back and forth to server?
 
Scott Shipp
Ranch Hand
Posts: 223
12
Eclipse IDE IntelliJ IDE Java Scala Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interestingly enough, I found that request.getHeader("cookie") did contain the cookie I'm looking for. I'll just use that instead of request.getCookies().

Weird.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!