aspose file tools*
The moose likes Servlets and the fly likes Cookie Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cookie Problem" Watch "Cookie Problem" New topic
Author

Cookie Problem

Aashima Arora
Ranch Hand

Joined: Jun 15, 2010
Posts: 59

i do not understand when is the cookie first created in the browser in the following code;




when we have forwarded the response to the resource , doesn't that mean the response has not yet been commited and hence the cookie should be created when the response is commited i.e when the jsp file is processed? or may be something else? i checked after i clicked submit in this, the cookie was created,iam little bit confused about working of request dispatcher,can anyone kindly explain ., thank you


Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
Aashima Arora wrote:i do not understand when is the cookie first created in the browser


The cookie is not created in the browser; it is created in the server and stored in the browser. The server will encapsulate the cookie in a Set-Cookie response header. The server uses this header to ask the browser to store some state information locally. In this case, the server is asking the browser to store user information locally. If the browser decides to honour this server request i.e. if the user hasn't disabled cookies in his/her browser, then the browser will store the cookie locally. The browser will then send the cookie back to the server (in a Cookie request header) each time it communicates with the same server.
Aashima Arora
Ranch Hand

Joined: Jun 15, 2010
Posts: 59

iam so sorry for the wrong question, i meant to ask when does the cookie first appear in the browser? i realize that there is a set cookie header in response and in the request here is a cookie header . in this particular code only, when the request has been forwarded to the jsp, when is the response being send back to the client .? is it when the jsp page appears so @ that very moment the cookie is stored .

in the jsp


when i click on 'click me'
iam redirected to


can i retrieve cookies on the jsp page itself or when i send the request from this page, i can retrieve cookies only on the checkcookie servlet?

Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
when does the cookie first appear in the browser?


When the browser gets a response from the server. This response may come from a servlet or jsp.

can i retrieve cookies on the jsp page itself

When the user clicks a link on the jsp page, the jsp forwards the request to the servlet. At this point, the jsp can't access the cookies because the cookies haven't been created yet. After the servlet processes the request, the servlet may forward the request back to the same jsp page. At this point, the jsp may access the cookies.
Aashima Arora
Ranch Hand

Joined: Jun 15, 2010
Posts: 59

Got it ! RequestDispatcher kind of confused me a bit ..Thank you so much
Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookie Problem
 
Similar Threads
Testing Cookies
EL cookie Problem
"Type mismatch: cannot convert from Cookie to String"
'The requested resource is not available' error
Cookies example in HFSJ