0% found this document useful (0 votes)
20 views7 pages

6.4 Session Management-Cookie

Uploaded by

nihalpatil0021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views7 pages

6.4 Session Management-Cookie

Uploaded by

nihalpatil0021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Session Tracking

-Session simply means a particular interval of time.


-Session Tracking is a way to maintain state (data) of an user. It is also known as session management in servlet.
How Session Works-
There are four different techniques used by Servlet application for session management. They are as follows:
1.Cookies
2.Hidden form field
3.URL Rewriting
4.HttpSession
Cookies
-Cookies are small pieces of information that are sent in response from the web server to the client. Cookies are
the simplest technique used for storing client state.

How cookie works-


Types of Cookie
1. Non-persistent cookie-
-It is valid for single session only. It is removed each time when user closes the browser.
2. Persistent cookie
- It is valid for multiple session . It is not removed each time when user closes the browser. It is removed only if
user logout or signout
Advantage of Cookies-
1. Simplest technique of maintaining the state.
2.Cookies are maintained at client side.
Disadvantage of Cookies-
1.It will not work if cookie is disabled from the browser.
2.Only textual information can be set in Cookie object.
Cookie API- javax.servlet.http.Cookie
Constructor of Cookie class
1.Cookie() 2. Cookie(String name, String value)
Methods of Cookie class-
1. public void setMaxAge(int expiry)- Sets the maximum age of the cookie in seconds.
2. public String getName()-Returns the name of the cookie.
3. public String getValue()-Returns the value of the cookie.
4. public void setName(String name)-changes the name of the cookie.
5. public void setValue(String value)-changes the value of the cookie.
6. Public String getPath()- Returns the path on the server to which the browser returns this cookie
How to create Cookie
Example-

You might also like