• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help with cookie

 
aryan sahu
Greenhorn
Posts: 11
Chrome Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, i am very much confused with this cookie thing.For state management HttpSession objects are created in containers and a session id is assigned to it.
I understand this is used to identify the client request , i mean i am confused if session id's are encapsulated in cookies and are passed to client in response.

does this statement creates a cookie the background

HttpSession s=request.getSession();

or Cookie ck=new Cookie("name",value); i am confused...help!
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically cookies are used to store simple text information on the client which gives the server some a-priori information about the client when a request comes in.
Like the "remember me on this computer" checkbox or your language preference for that site when you access it from the same machine and same browser.
Session Id is one such information that is passed through cookies provided the client browser has not disabled them.

Now to answer your original questions
aryan sahu wrote:
does this statement creates a cookie the background

HttpSession s=request.getSession();

or Cookie ck=new Cookie("name",value);


Statement 1: Yes. It does create new cookie which will store the session id but only after the response is given back to the client.

Statement 2: No. This cookie is not created on the browser until you say response.addCookie(ck); assuming response is your servlet's response object.

Hope this helps
 
abani patra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I agree with Amit Ghorpade.
I want to just add that with the first time request the cookie will not be in request after onward on every request you can have the cookie value in your request.
 
Aniket S. Kulkarni
Ranch Hand
Posts: 87
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The below links may help you.

Cookie
session
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic