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