File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Cookie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cookie" Watch "Cookie" New topic


Krishan Chauhan
Ranch Hand

Joined: Mar 12, 2008
Posts: 32
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");
Cookie[] cookies = request.getKookies(); // read 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?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 61089

The cookie, which is a client-side concept, is not created until the response is returned back to the client

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Cookie