Servlet Cookie

Cookie is a class that is used for session management. It contains a small amount of information which persists between the server and client.  This information includes name, value and other attributes.

Servlet send this information to web browser and browser saved it so that whenever browser makes a request then it also sends this information along with it. Thus through cookies a server can easily identify a client.

Methods of Cookie

                   Method

               Description

String getName()

This method returns the name of cookie.

String getValue()

This method returns the current value of cookie.

void setValue(String name)

We can set the value of cookie using this method.

void setMaxAge(int i)

This method is used to set the maximum age of cookie after which the session becomes expire.

int getMaxAge()

This method returns the maximum age of a cookie.