permaculture playing cards*
The moose likes Servlets and the fly likes Cookie in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cookie in Servlet" Watch "Cookie in Servlet" New topic
Author

Cookie in Servlet

Rahul Chandran
Greenhorn

Joined: Oct 14, 2010
Posts: 18
Hi,
I want to learn the use of Cookie in Java .
What is the use of Cookie..?
Can someone give me a simple example of how to write to a cookie nd read from the same cookie..??

Thanks.
Regards,
Rahul.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Welcome to JavaRanch!
Rahul Chandran wrote:
What is the use of Cookie..?

Cookie is used to store some temporary information on the Client side.
Rahul Chandran wrote:
Can someone give me a simple example of how to write to a cookie nd read from the same cookie..??

Have a look on HttpServletResponse and HttpServletRequest APIs for the details~!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

Rahul Chandran wrote:Hi,
I want to learn the use of Cookie in Java .
What is the use of Cookie..?
Can someone give me a simple example of how to write to a cookie nd read from the same cookie..??

Thanks.
Regards,
Rahul.


Cookie is one of the popular ways of session management. Though other mechanisms do exist.

When the client (any browser for instance) sends the request for the first time , a cookie is created, loaded with session identifier and sends back along with the response (all done behind the scenes). On subsequent requests, client would send the cookie along with the request, so that servlet can identify if the request belongs to the same old session or not.

You as a developer can also create a cookie object and stuff them with values. Ideally it is like a map having key/value pair..


Regards
KumarRaja

Rahul Chandran
Greenhorn

Joined: Oct 14, 2010
Posts: 18
Thanks..
But an Example would be more understandable..!!
Any way Thank You All..!!
 
 
subject: Cookie in Servlet
 
Similar Threads
Alternative to Cookie?
how do i use the cookies??
Single login for a Particular url
transfer from jsp to servlet
How to Check If Cookies are Enabled/Disabled