SlideShare a Scribd company logo
SESSION – 10
By→ Anuj Kumar Singh
Cookies in Servlet
1. A cookie is a small piece of information that is persisted between
the multiple client requests.
2. A cookie has a name, a single value, and optional attributes such
as a comment, path and domain qualifiers, a maximum age, and a
version number.
How Cookie works
By default, each request is considered as a new request.
1. In cookies technique, we add cookie with response from the
servlet.
2. So cookie is stored in the cache of the browser. After that if request
is sent by the user, cookie is added with request by default.
3. Thus, we recognize the user as the old user.
Types of Cookie
1. Non-persistent cookie
2. Persistent 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.
Cookies class
javax.servlet.http.Cookie class provides the functionality of using
cookies. It provides a lot of useful methods for cookies.
Constructor Description
Cookie() constructs a cookie.
Cookie(String name, String value) constructs a cookie with a specified name and
value.
Useful methods of Cookies
Method Description
public void setMaxAge(int expiry) Sets the maximum age of the cookie in
seconds.
public String getName() Returns the name of the cookie. The name
cannot be changed after creation.
public String getValue() Returns the value of the cookie.
public void setName(String name) changes the name of the cookie.
public void setValue(String value) changes the value of the cookie.
Other methods required for using Cookies
For adding cookie or getting the value from the cookie, we need
some methods provided by other interfaces.
1. public void addCookie(Cookie ck): method of HttpServletResponse
interface is used to add cookie in response object.
2. public Cookie[] getCookies(): method of HttpServletRequest
interface is used to return all the cookies from the browser.
How to create Cookie?
Cookie ck=new Cookie("user",“anuj rajput");//creating cookie object
response.addCookie(ck);//adding cookie in the response
How to delete Cookie?
The simple code to delete cookie. It is mainly used to logout or
signout the user.
Cookie ck=new Cookie("user",""); //deleting value of cookie
ck.setMaxAge(0); //changing the maximum age to 0 seconds
response.addCookie(ck); //adding cookie in the response
How to get Cookies?
Cookie ck[]=request.getCookies();
for(int i=0;i<ck.length;i++)
{ out.print("<br>"+ck[i].getName()+" "+ck[i].getValue());//printing name
and value of cookie }
Example
a. NewServlet.java
b. NewServlet1.java
Output
Servlet   session 10
Servlet   session 10

More Related Content

What's hot

Internet Cookies
Internet CookiesInternet Cookies
Internet Cookies
anita gouda
 
Cookies: HTTP state management mechanism
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanism
Jivan Nepali
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
Aashish Ghale
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
Programmer Blog
 
Cookies & Session
Cookies & SessionCookies & Session
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
Nisa Soomro
 
Introduction to php web programming - sessions and cookies
Introduction to php   web programming - sessions and cookiesIntroduction to php   web programming - sessions and cookies
Introduction to php web programming - sessions and cookies
baabtra.com - No. 1 supplier of quality freshers
 
Cookies-PHP
Cookies-PHPCookies-PHP
Cookies-PHP
priyavanim
 
java Cookies
java Cookiesjava Cookies
java Cookies
Rajanivetha G
 
PHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and SessionsPHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and Sessions
Vibrant Technologies & Computers
 
Php Sessoins N Cookies
Php Sessoins N CookiesPhp Sessoins N Cookies
Php Sessoins N Cookies
mussawir20
 
Cookies and Session
Cookies and SessionCookies and Session
Cookies and Session
KoraStats
 
Session tracking In Java
Session tracking In JavaSession tracking In Java
Session tracking In Java
honeyvachharajani
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In Php
Harit Kothari
 
Sessions in php
Sessions in php Sessions in php
Sessions in php
Mudasir Syed
 
Linux fundamental - Chap 13 account management
Linux fundamental - Chap 13 account managementLinux fundamental - Chap 13 account management
Linux fundamental - Chap 13 account management
Kenny (netman)
 

What's hot (16)

Internet Cookies
Internet CookiesInternet Cookies
Internet Cookies
 
Cookies: HTTP state management mechanism
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanism
 
Cookie and session
Cookie and sessionCookie and session
Cookie and session
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
 
Cookies & Session
Cookies & SessionCookies & Session
Cookies & Session
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
 
Introduction to php web programming - sessions and cookies
Introduction to php   web programming - sessions and cookiesIntroduction to php   web programming - sessions and cookies
Introduction to php web programming - sessions and cookies
 
Cookies-PHP
Cookies-PHPCookies-PHP
Cookies-PHP
 
java Cookies
java Cookiesjava Cookies
java Cookies
 
PHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and SessionsPHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and Sessions
 
Php Sessoins N Cookies
Php Sessoins N CookiesPhp Sessoins N Cookies
Php Sessoins N Cookies
 
Cookies and Session
Cookies and SessionCookies and Session
Cookies and Session
 
Session tracking In Java
Session tracking In JavaSession tracking In Java
Session tracking In Java
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In Php
 
Sessions in php
Sessions in php Sessions in php
Sessions in php
 
Linux fundamental - Chap 13 account management
Linux fundamental - Chap 13 account managementLinux fundamental - Chap 13 account management
Linux fundamental - Chap 13 account management
 

Similar to Servlet session 10

Cookies in servlet
Cookies in servletCookies in servlet
Cookies in servlet
chauhankapil
 
Authentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxAuthentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptx
Knoldus Inc.
 
SessionTrackServlets.pptx
SessionTrackServlets.pptxSessionTrackServlets.pptx
SessionTrackServlets.pptx
Ranjeet Reddy
 
Cookies in Angular | Install CookiesService
Cookies in Angular | Install CookiesServiceCookies in Angular | Install CookiesService
Cookies in Angular | Install CookiesService
Pradeep Kumar
 
Enterprise java unit-2_chapter-2
Enterprise  java unit-2_chapter-2Enterprise  java unit-2_chapter-2
Enterprise java unit-2_chapter-2
sandeep54552
 
07 cookies
07 cookies07 cookies
07 cookies
snopteck
 
Sessions&cookies
Sessions&cookiesSessions&cookies
Sessions&cookies
Tirthika Bandi
 
Java - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionJava - Servlet - Mazenet Solution
Java - Servlet - Mazenet Solution
Mazenetsolution
 
Cookie replay attack unit wise presentation
Cookie replay attack  unit wise presentationCookie replay attack  unit wise presentation
Cookie replay attack unit wise presentation
Nilu Desai
 
ASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and CookiesASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and Cookies
baabtra.com - No. 1 supplier of quality freshers
 
State management servlet
State management servletState management servlet
State management servlet
Thakur Amit Tomer
 
PHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONSPHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONS
Degu8
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
Lena Petsenchuk
 
lecture 12.pptx
lecture 12.pptxlecture 12.pptx
lecture 12.pptx
ITNet
 
Maker Checker -Incorporating Multiple Roles in Single SilkPerformer script
Maker Checker -Incorporating Multiple Roles in Single SilkPerformer scriptMaker Checker -Incorporating Multiple Roles in Single SilkPerformer script
Maker Checker -Incorporating Multiple Roles in Single SilkPerformer script
Swarnkar Rajesh
 
What Is Evercookie and Why You Should Avoid It for Privacy’s Sake
What Is Evercookie and Why You Should Avoid It for Privacy’s SakeWhat Is Evercookie and Why You Should Avoid It for Privacy’s Sake
What Is Evercookie and Why You Should Avoid It for Privacy’s Sake
Piwik PRO
 
Using cookies and sessions
Using cookies and sessionsUsing cookies and sessions
Using cookies and sessions
Nuha Noor
 
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
kalichargn70th171
 
Adv java unit 4 M.Sc CS.pdf
Adv java unit 4 M.Sc CS.pdfAdv java unit 4 M.Sc CS.pdf
Adv java unit 4 M.Sc CS.pdf
KALAISELVI P
 
Session and cookies,get and post methods
Session and cookies,get and post methodsSession and cookies,get and post methods
Session and cookies,get and post methods
baabtra.com - No. 1 supplier of quality freshers
 

Similar to Servlet session 10 (20)

Cookies in servlet
Cookies in servletCookies in servlet
Cookies in servlet
 
Authentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxAuthentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptx
 
SessionTrackServlets.pptx
SessionTrackServlets.pptxSessionTrackServlets.pptx
SessionTrackServlets.pptx
 
Cookies in Angular | Install CookiesService
Cookies in Angular | Install CookiesServiceCookies in Angular | Install CookiesService
Cookies in Angular | Install CookiesService
 
Enterprise java unit-2_chapter-2
Enterprise  java unit-2_chapter-2Enterprise  java unit-2_chapter-2
Enterprise java unit-2_chapter-2
 
07 cookies
07 cookies07 cookies
07 cookies
 
Sessions&cookies
Sessions&cookiesSessions&cookies
Sessions&cookies
 
Java - Servlet - Mazenet Solution
Java - Servlet - Mazenet SolutionJava - Servlet - Mazenet Solution
Java - Servlet - Mazenet Solution
 
Cookie replay attack unit wise presentation
Cookie replay attack  unit wise presentationCookie replay attack  unit wise presentation
Cookie replay attack unit wise presentation
 
ASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and CookiesASP.NET-Web Programming - Sessions and Cookies
ASP.NET-Web Programming - Sessions and Cookies
 
State management servlet
State management servletState management servlet
State management servlet
 
PHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONSPHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONS
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
lecture 12.pptx
lecture 12.pptxlecture 12.pptx
lecture 12.pptx
 
Maker Checker -Incorporating Multiple Roles in Single SilkPerformer script
Maker Checker -Incorporating Multiple Roles in Single SilkPerformer scriptMaker Checker -Incorporating Multiple Roles in Single SilkPerformer script
Maker Checker -Incorporating Multiple Roles in Single SilkPerformer script
 
What Is Evercookie and Why You Should Avoid It for Privacy’s Sake
What Is Evercookie and Why You Should Avoid It for Privacy’s SakeWhat Is Evercookie and Why You Should Avoid It for Privacy’s Sake
What Is Evercookie and Why You Should Avoid It for Privacy’s Sake
 
Using cookies and sessions
Using cookies and sessionsUsing cookies and sessions
Using cookies and sessions
 
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
 
Adv java unit 4 M.Sc CS.pdf
Adv java unit 4 M.Sc CS.pdfAdv java unit 4 M.Sc CS.pdf
Adv java unit 4 M.Sc CS.pdf
 
Session and cookies,get and post methods
Session and cookies,get and post methodsSession and cookies,get and post methods
Session and cookies,get and post methods
 

More from Anuj Singh Rajput

Web technology
Web technologyWeb technology
Web technology
Anuj Singh Rajput
 
Java script
Java scriptJava script
Java script
Anuj Singh Rajput
 
Html (hypertext markup language)
Html (hypertext markup language)Html (hypertext markup language)
Html (hypertext markup language)
Anuj Singh Rajput
 
Css
CssCss
Bootstrap
BootstrapBootstrap
Jsp session 13
Jsp   session 13Jsp   session 13
Jsp session 13
Anuj Singh Rajput
 
Jsp session 12
Jsp   session 12Jsp   session 12
Jsp session 12
Anuj Singh Rajput
 
Jsp session 11
Jsp   session 11Jsp   session 11
Jsp session 11
Anuj Singh Rajput
 
Jsp session 10
Jsp   session 10Jsp   session 10
Jsp session 10
Anuj Singh Rajput
 
Jsp session 9
Jsp   session 9Jsp   session 9
Jsp session 9
Anuj Singh Rajput
 
Jsp session 8
Jsp   session 8Jsp   session 8
Jsp session 8
Anuj Singh Rajput
 
Jsp session 7
Jsp   session 7Jsp   session 7
Jsp session 7
Anuj Singh Rajput
 
Jsp session 6
Jsp   session 6Jsp   session 6
Jsp session 6
Anuj Singh Rajput
 
Jsp session 5
Jsp   session 5Jsp   session 5
Jsp session 5
Anuj Singh Rajput
 
Jsp session 4
Jsp   session 4Jsp   session 4
Jsp session 4
Anuj Singh Rajput
 
Jsp session 3
Jsp   session 3Jsp   session 3
Jsp session 3
Anuj Singh Rajput
 
Jsp session 2
Jsp   session 2Jsp   session 2
Jsp session 2
Anuj Singh Rajput
 
Jsp session 1
Jsp   session 1Jsp   session 1
Jsp session 1
Anuj Singh Rajput
 
Servlet session 14
Servlet   session 14Servlet   session 14
Servlet session 14
Anuj Singh Rajput
 
Servlet session 13
Servlet   session 13Servlet   session 13
Servlet session 13
Anuj Singh Rajput
 

More from Anuj Singh Rajput (20)

Web technology
Web technologyWeb technology
Web technology
 
Java script
Java scriptJava script
Java script
 
Html (hypertext markup language)
Html (hypertext markup language)Html (hypertext markup language)
Html (hypertext markup language)
 
Css
CssCss
Css
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Jsp session 13
Jsp   session 13Jsp   session 13
Jsp session 13
 
Jsp session 12
Jsp   session 12Jsp   session 12
Jsp session 12
 
Jsp session 11
Jsp   session 11Jsp   session 11
Jsp session 11
 
Jsp session 10
Jsp   session 10Jsp   session 10
Jsp session 10
 
Jsp session 9
Jsp   session 9Jsp   session 9
Jsp session 9
 
Jsp session 8
Jsp   session 8Jsp   session 8
Jsp session 8
 
Jsp session 7
Jsp   session 7Jsp   session 7
Jsp session 7
 
Jsp session 6
Jsp   session 6Jsp   session 6
Jsp session 6
 
Jsp session 5
Jsp   session 5Jsp   session 5
Jsp session 5
 
Jsp session 4
Jsp   session 4Jsp   session 4
Jsp session 4
 
Jsp session 3
Jsp   session 3Jsp   session 3
Jsp session 3
 
Jsp session 2
Jsp   session 2Jsp   session 2
Jsp session 2
 
Jsp session 1
Jsp   session 1Jsp   session 1
Jsp session 1
 
Servlet session 14
Servlet   session 14Servlet   session 14
Servlet session 14
 
Servlet session 13
Servlet   session 13Servlet   session 13
Servlet session 13
 

Recently uploaded

Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 

Recently uploaded (20)

Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 

Servlet session 10

  • 1. SESSION – 10 By→ Anuj Kumar Singh
  • 2. Cookies in Servlet 1. A cookie is a small piece of information that is persisted between the multiple client requests. 2. A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number. How Cookie works By default, each request is considered as a new request. 1. In cookies technique, we add cookie with response from the servlet. 2. So cookie is stored in the cache of the browser. After that if request is sent by the user, cookie is added with request by default. 3. Thus, we recognize the user as the old user.
  • 3. Types of Cookie 1. Non-persistent cookie 2. Persistent 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.
  • 4. 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.
  • 5. Cookies class javax.servlet.http.Cookie class provides the functionality of using cookies. It provides a lot of useful methods for cookies. Constructor Description Cookie() constructs a cookie. Cookie(String name, String value) constructs a cookie with a specified name and value.
  • 6. Useful methods of Cookies Method Description public void setMaxAge(int expiry) Sets the maximum age of the cookie in seconds. public String getName() Returns the name of the cookie. The name cannot be changed after creation. public String getValue() Returns the value of the cookie. public void setName(String name) changes the name of the cookie. public void setValue(String value) changes the value of the cookie.
  • 7. Other methods required for using Cookies For adding cookie or getting the value from the cookie, we need some methods provided by other interfaces. 1. public void addCookie(Cookie ck): method of HttpServletResponse interface is used to add cookie in response object. 2. public Cookie[] getCookies(): method of HttpServletRequest interface is used to return all the cookies from the browser. How to create Cookie? Cookie ck=new Cookie("user",“anuj rajput");//creating cookie object response.addCookie(ck);//adding cookie in the response
  • 8. How to delete Cookie? The simple code to delete cookie. It is mainly used to logout or signout the user. Cookie ck=new Cookie("user",""); //deleting value of cookie ck.setMaxAge(0); //changing the maximum age to 0 seconds response.addCookie(ck); //adding cookie in the response How to get Cookies? Cookie ck[]=request.getCookies(); for(int i=0;i<ck.length;i++) { out.print("<br>"+ck[i].getName()+" "+ck[i].getValue());//printing name and value of cookie }
  • 9.