Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes Cookie question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cookie question" Watch "Cookie question" New topic
Author

Cookie question

B Mistry
Greenhorn

Joined: Jul 07, 2011
Posts: 2
Hi All,

I have some problems regarding the cookie.

I am setting a cookie in the server code as:

name: name:value
path: "/"

When i send an http request, I see that the cookie is received in the response but for all consecutive requests the browser should send the same cookie in the http request right ? I see that the cookie is not sent to the server.

I don't think there is a control in the browser which enables or disables the cookie which is sent in the request.. please correct me if i am wrong.

So my question is, how do I make the browser send the cookie in the request which was previously received and set into the cookie repository??

Thanks in advance.
elvadas nono
Greenhorn

Joined: Jul 04, 2011
Posts: 12
Hi Guy Can you post a piece of code?
You set a cookie in the HttpResponse instance using response.addCookie(Cookie cookie);
and the cookie has a set of fields like name,value,comments.
Cookies are sent from the client to the server for each requestt as key name pair name/value, fields like comments are not sent to the servers.
first of all ensure that you fill the cookie properly.
In further, cookies which has the property httpOnly set to true are not exposed to client side scripting.
so you can transfered them to servers only by an HTTP request.

B Mistry
Greenhorn

Joined: Jul 07, 2011
Posts: 2
elvadas nono wrote:Hi Guy Can you post a piece of code?
You set a cookie in the HttpResponse instance using response.addCookie(Cookie cookie);
and the cookie has a set of fields like name,value,comments.
Cookies are sent from the client to the server for each requestt as key name pair name/value, fields like comments are not sent to the servers.
first of all ensure that you fill the cookie properly.
In further, cookies which has the property httpOnly set to true are not exposed to client side scripting.
so you can transfered them to servers only by an HTTP request.



elvadas,

I figured it out. I was using the ip address in the url instead of full hostname and that was the problem. All my consecutive requests were not picking up the cookie from the browser repository but now its ok.

Thanks for your response.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookie question