This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cookie in Servlet

 
Rahul Chandran
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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~!
 
Kumar Raja
Ranch Hand
Posts: 547
2
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Rahul Chandran
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks..
But an Example would be more understandable..!!
Any way Thank You All..!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic