Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cookie  RSS feed

 
Krishan Chauhan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I have a doubt with Cookie. I have the following code in my Servlet's doGet() method:

Cookie cookie = new Cookie("username", "Sachin");
response.addCookie(cookie);
Cookie[] cookies = request.getKookies(); // read Cookies
out.println(cookies);

Now, when i am Invoking the Servlet for the first time, request.getKookies() method returns null, but for the subsequent request it is returing the Cookie Object. Could anybody tell me the reason for this?
Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The cookie, which is a client-side concept, is not created until the response is returned back to the client
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!