SlideShare a Scribd company logo
Servlet life cycle
Presented By: Chandni Gupta
Student Code: BWU/MCA/22/119
Course Name: Master Of Computer Application
Department: Computational Science
Department of Computational Sciences
CONTENT
• Servlet
• Servlet lifecycle diagram
• Methods of lifecycle
.init()
.service()
.doGet()
.doPost()
.destroy()
Department of Computational Sciences
SERVLET
 Servlet is java class which extends the functionality of web
server by dynamically generating web pages.
 Servlet technology is used to create Dynamic web application.
 Servlet technology is robust and scalable.
Department of Computational Sciences
SERVLET LIFE CYCLE
Department of Computational Sciences
SERVLET LIFE CYCLE:init()
 Servlet class is loaded
The class loader is responsible to load the servlet class.
The servlet class is loaded when the first request for the servlet is received by the web container.
 Servlet instance is created
The web container creates the instance of a servlet after loading the servlet class.
The servlet instance is created only once in the servlet life cycle.
 Init method is invoked
The web container calls the init method only once after creating the servlet instance.
The init method is used to initialize the servlet.
 Syntax:
public void init(ServletConfig config) throws ServletException
{ //initialization
}
Department of Computational Sciences
SERVLET LIFE CYCLE: Service()
 The service() method is the main method to perform the actual task.
 The servlet container calls the service() method to handle requests
coming from the client and to write the response back to the client.
 The service() method checks the HTTP request type (GET, POST,
PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc.
methods as appropriate.
 The doGet() and doPost() are most frequently used methods with in
each service request.
Department of Computational Sciences
Service:doGet()
 A GET request results from request for a URL or from an HTML form,
should be handled by doGet() method.
 doGet() shall be used when small amount of data and insensitive
data like a query has to be sent as a request.
 Syntax:
public void doGet
(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{
// Servlet code ...
} Department of Computational Sciences
Service:doPost()
 A POST request results from an HTML form that specifically lists
POST as the METHOD and it should be handled by doPost() method.
 doPost() shall be used when comparatively large amount of
sensitive data has to be sent.
 Syntax:
public void doPost (HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
// Servlet code ...
}
Department of Computational Sciences
Servlet Life Cycle: Destroy()
 The destroy() method is called only once at the end of the life cycle of a
servlet.
 This method gives your servlet a chance to close
i. database connections,
ii. halt background threads, and
iii. perform other such cleanup activities.
 Syntax:
public void destroy()
{
//Finalization code…
}
Department of Computational Sciences
REFERENCE
 “Core Java” by Dr. R. Nageswara Rao.
 https://www.javatpoint.com/life-cycle-of-a-servlet/
 https://www.geeksforgeeks.org/life-cycle-of-a-servlet/
Department of Computational Sciences
Department of Computational Sciences

More Related Content

Similar to SevletLifeCycle

J2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environmentJ2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environment
joearunraja2
 
Java servlets
Java servletsJava servlets
Java servlets
yuvarani p
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
Vikas Jagtap
 
LIFE CYCLE OF SERVLET
LIFE CYCLE OF SERVLETLIFE CYCLE OF SERVLET
LIFE CYCLE OF SERVLET
keerthikaA8
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
Venkateswara Rao N
 
servlet_lifecycle.pdf
servlet_lifecycle.pdfservlet_lifecycle.pdf
servlet_lifecycle.pdf
DrKowsalyaSaravanan
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
team11vgnt
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
Ankit Minocha
 
Web Technologies -- Servlets 4 unit slides
Web Technologies -- Servlets   4 unit slidesWeb Technologies -- Servlets   4 unit slides
Web Technologies -- Servlets 4 unit slides
Sasidhar Kothuru
 
Servlets
ServletsServlets
Dynamic content generation
Dynamic content generationDynamic content generation
Dynamic content generationEleonora Ciceri
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
PawanMM
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technologyvikram singh
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
bharathiv53
 
IP UNIT III PPT.pptx
 IP UNIT III PPT.pptx IP UNIT III PPT.pptx
IP UNIT III PPT.pptx
ssuser92282c
 

Similar to SevletLifeCycle (20)

Lecture 2
Lecture 2Lecture 2
Lecture 2
 
J2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environmentJ2EE : Java servlet and its types, environment
J2EE : Java servlet and its types, environment
 
Java servlets
Java servletsJava servlets
Java servlets
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
 
LIFE CYCLE OF SERVLET
LIFE CYCLE OF SERVLETLIFE CYCLE OF SERVLET
LIFE CYCLE OF SERVLET
 
Servlets
ServletsServlets
Servlets
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
servlet_lifecycle.pdf
servlet_lifecycle.pdfservlet_lifecycle.pdf
servlet_lifecycle.pdf
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
 
Web Technologies -- Servlets 4 unit slides
Web Technologies -- Servlets   4 unit slidesWeb Technologies -- Servlets   4 unit slides
Web Technologies -- Servlets 4 unit slides
 
Servlets
ServletsServlets
Servlets
 
Servlet11
Servlet11Servlet11
Servlet11
 
Dynamic content generation
Dynamic content generationDynamic content generation
Dynamic content generation
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
 
IP UNIT III PPT.pptx
 IP UNIT III PPT.pptx IP UNIT III PPT.pptx
IP UNIT III PPT.pptx
 

Recently uploaded

weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 

Recently uploaded (20)

weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 

SevletLifeCycle

  • 1. Servlet life cycle Presented By: Chandni Gupta Student Code: BWU/MCA/22/119 Course Name: Master Of Computer Application Department: Computational Science Department of Computational Sciences
  • 2. CONTENT • Servlet • Servlet lifecycle diagram • Methods of lifecycle .init() .service() .doGet() .doPost() .destroy() Department of Computational Sciences
  • 3. SERVLET  Servlet is java class which extends the functionality of web server by dynamically generating web pages.  Servlet technology is used to create Dynamic web application.  Servlet technology is robust and scalable. Department of Computational Sciences
  • 4. SERVLET LIFE CYCLE Department of Computational Sciences
  • 5. SERVLET LIFE CYCLE:init()  Servlet class is loaded The class loader is responsible to load the servlet class. The servlet class is loaded when the first request for the servlet is received by the web container.  Servlet instance is created The web container creates the instance of a servlet after loading the servlet class. The servlet instance is created only once in the servlet life cycle.  Init method is invoked The web container calls the init method only once after creating the servlet instance. The init method is used to initialize the servlet.  Syntax: public void init(ServletConfig config) throws ServletException { //initialization } Department of Computational Sciences
  • 6. SERVLET LIFE CYCLE: Service()  The service() method is the main method to perform the actual task.  The servlet container calls the service() method to handle requests coming from the client and to write the response back to the client.  The service() method checks the HTTP request type (GET, POST, PUT, DELETE, etc.) and calls doGet, doPost, doPut, doDelete, etc. methods as appropriate.  The doGet() and doPost() are most frequently used methods with in each service request. Department of Computational Sciences
  • 7. Service:doGet()  A GET request results from request for a URL or from an HTML form, should be handled by doGet() method.  doGet() shall be used when small amount of data and insensitive data like a query has to be sent as a request.  Syntax: public void doGet (HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { // Servlet code ... } Department of Computational Sciences
  • 8. Service:doPost()  A POST request results from an HTML form that specifically lists POST as the METHOD and it should be handled by doPost() method.  doPost() shall be used when comparatively large amount of sensitive data has to be sent.  Syntax: public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Servlet code ... } Department of Computational Sciences
  • 9. Servlet Life Cycle: Destroy()  The destroy() method is called only once at the end of the life cycle of a servlet.  This method gives your servlet a chance to close i. database connections, ii. halt background threads, and iii. perform other such cleanup activities.  Syntax: public void destroy() { //Finalization code… } Department of Computational Sciences
  • 10. REFERENCE  “Core Java” by Dr. R. Nageswara Rao.  https://www.javatpoint.com/life-cycle-of-a-servlet/  https://www.geeksforgeeks.org/life-cycle-of-a-servlet/ Department of Computational Sciences