• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help with cookie

 
Greenhorn
Posts: 11
Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 87
Android Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The below links may help you.

Cookie
session
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic