JSP Cookies ConceptPritesh
Concept of Cookies :
- Cookies are basically text files stored on the client computer.
- Cookies are used for tracking purpose.
- JSP supports HTTP cookies using underlying technology using servlet.
Types of Cookies :
|Type of cookie||Explanation|
|Session cookies||Session cookies are created temporarily in your browser's sub-folder when you visit the website for first time , once you leave the site these cookies will be destroyed automatically.|
|Persistent cookies||Persistent cookies remain in the browser's sub-folder and activated when you re-visit the website. These cookies will be destroyed after the period set within the cookie's file|
Steps to identify whether user is returning or not ?
There are three steps involved in identifying returning users:
- Server script sends a set of cookies to the browser when user visits site for first time. Cookies contain name,identification number etc
- Cookies will stored in the browser’s folder
- When user re-visit the website next time, browser sends those cookies information to the server and server uses that information to identify the user
Example of the Cookie File :
HTTP/1.1 200 OK Date: Fri, 04 Feb 2014 11:01:38 GMT Server: Apache/1.3.9 (UNIX) PHP/4.0b3 Set-Cookie: name=pritesh; expires=Tuesday, 07-Oct-14 12:33:31 GMT; path=/; domain=c4learn.com Connection: close Content-Type: text/html
You can see the name-value pair in the cookie file.Cookie file contain GMT date, a path and a domain and expiration date.
Below is the example of the HTTP header that we send when user revisit the website.
GET / HTTP/1.0 Connection: Keep-Alive User-Agent: Mozilla/4.6 (X11; I; Linux 2.2.6-15apmac ppc) Host: zink.demon.co.uk:1126 Accept: image/gif, */* Accept-Encoding: gzip Accept-Language: en Accept-Charset: iso-8859-1,*,utf-8 Cookie: name=xyz