Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




Java interview questions: - What do you mean by cookies?

Cookies are piece of data which are stored at the client’s browser to track information regarding the user usage and habits. Servlets sends cookies to the browser client using the HTTP response headers. When client gets the cookie information it’s stored by the browser in the client’s hard disk. Similarly client returns the cookie information using the HTTP request headers.

Figure: - Cookies in action

Figure: - Cookies code walkthrough

Above is a simple snippet which shows how to use cookies. To create a cookie you need to use the “Cookie” class. In the above snippet step1 creates a cookie using the “Cookie” class. In this case “favoritecookiebook” is the name of the cookie. In Step 2 you can see how a cookie has been added to the response. Step 3 code shows how to get all the cookies which has come in the current request header. Step 4 shows the way to get a cookie from a collection in this case we wanted to retrieve “favoritecookiebook” from the cookies collection.

See the following video on Java which describes Batch processing in Hibernate: -

Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions

Share this article   |    Print    |    Article read by 5882 times
Author:
Shivprasad Koirala
We conduct training for Java/J2EE technologies like design patterns, J2EE, Struts, Hibernate, Spring, Rich Interface etc. and likes to write articles on the same in free time.
Related Articles: No related article
Related Interview Questions: No related interview question