It is used to perform the Client-side state management process, a cookie is used to store server-side data under the client machine for a particular browser.
The cookie will be private because it will be stored on a particular browser under the operating system cookie folder which will be managed by a web browser separately.
When we create Session Data then the cookie will be created automatically.
Remember me option will be created by cookie.
Syntax to create cookie:-
Cookie ref = new Cookie(key,value);
ref.setMaxAge(time);
response.addCookie(ref);
Syntax to Get Data From Cookie:-
Cookie c[] = request.getCookies();
String s="",u="";
for(int i=0;i<c.length;i++)
{
if(c[i].getName().equals("cuid"))
{
s=c[i].getValue();
}
if(c[i].getName().equals("cpass"))
{
u=c[i].getValue();
}
}
When we create Session Data then the cookie will be created automatically.
Remember me option will be created by cookie.
Syntax to create cookie:-
Cookie ref = new Cookie(key,value);
ref.setMaxAge(time);
response.addCookie(ref);
Syntax to Get Data From Cookie:-
Cookie c[] = request.getCookies();
String s="",u="";
for(int i=0;i<c.length;i++)
{
if(c[i].getName().equals("cuid"))
{
s=c[i].getValue();
}
if(c[i].getName().equals("cpass"))
{
u=c[i].getValue();
}
}
POST Answer of Questions and ASK to Doubt