0% found this document useful (0 votes)
49 views2 pages

Cookies:: Cookie CK New Cookie ("Key","value")

Cookies are pieces of information sent from a web server and stored in a user's browser. To add a cookie, a developer creates a Cookie object with a key-value pair and adds it to the response sent back to the browser. To retrieve cookies, the developer uses the request object's getCookies() method, which returns an array of Cookie objects that can then be accessed by name and value.

Uploaded by

suganthi31
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views2 pages

Cookies:: Cookie CK New Cookie ("Key","value")

Cookies are pieces of information sent from a web server and stored in a user's browser. To add a cookie, a developer creates a Cookie object with a key-value pair and adds it to the response sent back to the browser. To retrieve cookies, the developer uses the request object's getCookies() method, which returns an array of Cookie objects that can then be accessed by name and value.

Uploaded by

suganthi31
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Cookies: Cookies are information that a Web server sends to a browser and that the browser returns back

to web server when visiting the same Web site later. Cookie can be saved in a browser as a key value pair To add a cookie in browser we need to create an object for cookie class and use a HttpResponse object to send the data to browser. To create cookie object: Cookie ck=new Cookie(key,value) To add cookie to browser response.addCookie(ck); // addCookie method takes cookie objects as argument

To get or retrieve the all the cookie present in the browser we need to use a HttpRequest object To get cookie: Cookie ck[]=request.getCookies();

To display cookie present in cookie array: for(int i=0;i<ck.length;i++) {String str=ck[i].getName(); String value=ck[i].getValue(); out.println("<b><br>Name of the Cookie :"+str); out.println("<b><br> Value of the cookie :"+value); }

You might also like