This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Servlets and the fly likes Cookie Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Cookie" Watch "Cookie" New topic
Author

Cookie

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");
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

Joined: Jan 10, 2002
Posts: 56554
    
  14

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookie
 
Similar Threads
Auto Login with Container Managed Security
Persistent Cookies with Servlets
Regarding Cookies
about Cookies
How to set JSESSIONID's maxAge?