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..??
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..