SlideShare a Scribd company logo
Name: Dhrumil I. Panchal
Sem: 6th Semester
Subject: Advanced Java
Branch: Computer Engineering (B.E.)
Year: 2019-20
Servlet and Servlet Life Cycle
 Servlet
 Life Cycle of 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.
 In the life cycle of servlet there are three important
methods. These methods are
1. init()
2. service()
3. destroy()
 The client enters the URL in the web browser and makes
a request. The browser then generates the HTTP request
and sends it to the Web server.
 Web server maps this request to the corresponding
servlet.
 The server basically invokes the init() method of servlet. This
method is called only when the servlet is loaded in the
memory for the first time.
 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.
 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.
 The web container calls the init method only once after
creating the servlet instance. The init() method is used to
initialize the servlet.
public void init(ServletConfig config)throws
ServletException
{
//Servlet Initialization…
}
 A servlet configuration object used by a servlet container
to pass information to a servlet during initialization.
 The service() method is the main method to perform the
actual task.
 The servlet container (i.e. web server) calls the service()
method to handle requests coming from the client( browsers)
and to write the response back to the client.
 Each time the server receives a request for a servlet, the
server spawns a new thread and calls service.
public void service(ServletRequest request,
ServletResponse response) throws ServletException,
IOException
{
//Servlet Task
}
 Finally server unloads the servlet from the memory using
the destroy() method.
 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
1. database connections,
2. halt background threads,
3. write cookie lists or hit counts to disk, and
4. perform other such cleanup activities.
 After the destroy() method is called, the servlet object is
marked for garbage collection.
public void destroy()
{
// Finalization code...
}
import java.io.*;
import javax.servlet.*;
public class MyServlet1 extends GenericServlet
{
public void init() throws ServletException
{
//Initailization Code
}
public void service(ServletRequest request, ServletResponse response)
throws ServletException,IOException
{
//Servlet code
}
public void destroy()
{
//Finalization Code
}
}
 Inspiration from Prof. Jayna Shah
 Notes of AJAVA
 Textbook of AJAVA
 Images from Google Images
 Some my own Knowledge
class Thankyou
{
public static void main(String args[])
{
System.out.println(“Thank You”);
}
}

More Related Content

What's hot

MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
VINOTH R
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
amitksaha
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
Nahian Ahmed
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
sandeep54552
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postvamsi krishna
 
Applets in java
Applets in javaApplets in java
Applets in java
Wani Zahoor
 
Java servlets and CGI
Java servlets and CGIJava servlets and CGI
Java servlets and CGI
lavanya marichamy
 
Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3
sandeep54552
 
Event handling
Event handlingEvent handling
Event handling
swapnac12
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
Rajkumarsoy
 
Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packagesvamsi krishna
 
Jsp lifecycle
Jsp   lifecycleJsp   lifecycle
Jsp lifecycle
chauhankapil
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
Halil Burak Cetinkaya
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMSkoolkampus
 
Struts
StrutsStruts
Struts
s4al_com
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
Kumar
 
Java applets
Java appletsJava applets
Java applets
Khan Mac-arther
 

What's hot (20)

MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Servletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,postServletarchitecture,lifecycle,get,post
Servletarchitecture,lifecycle,get,post
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Java servlets and CGI
Java servlets and CGIJava servlets and CGI
Java servlets and CGI
 
Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3
 
Event handling
Event handlingEvent handling
Event handling
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
Javax.servlet,http packages
Javax.servlet,http packagesJavax.servlet,http packages
Javax.servlet,http packages
 
Jsp lifecycle
Jsp   lifecycleJsp   lifecycle
Jsp lifecycle
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
 
Struts
StrutsStruts
Struts
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Java applets
Java appletsJava applets
Java applets
 

Similar to Servlet and Servlet Life Cycle

LIFE CYCLE OF SERVLET
LIFE CYCLE OF SERVLETLIFE CYCLE OF SERVLET
LIFE CYCLE OF SERVLET
keerthikaA8
 
Servlet lifecycle
Servlet  lifecycleServlet  lifecycle
Servlet lifecycle
chauhankapil
 
J2ee servlet
J2ee servletJ2ee servlet
J2ee servlet
vinoth ponnurangam
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
Vikas Jagtap
 
IP UNIT III PPT.pptx
 IP UNIT III PPT.pptx IP UNIT III PPT.pptx
IP UNIT III PPT.pptx
ssuser92282c
 
ajava unit 1.pptx
ajava unit 1.pptxajava unit 1.pptx
ajava unit 1.pptx
PawanKumar617960
 
WEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES ServletWEB TECHNOLOGIES Servlet
Java Servlet
Java ServletJava Servlet
Java Servlet
Yoga Raja
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
team11vgnt
 
Servlet session 2
Servlet   session 2Servlet   session 2
Servlet session 2
Anuj Singh Rajput
 
S E R V L E T S
S E R V L E T SS E R V L E T S
S E R V L E T Spatinijava
 
J servlets
J servletsJ servlets
J servlets
reddivarihareesh
 
Servlets
ServletsServlets
Servlets & jdbc
Servlets & jdbcServlets & jdbc
Servlets & jdbc
Siva Priya
 
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
 
SevletLifeCycle
SevletLifeCycleSevletLifeCycle
SevletLifeCycle
Chandnigupta80
 
servlet in java
servlet in javaservlet in java
servlet in java
sowfi
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
ssbd6985
 
Servletand sessiontracking
Servletand sessiontrackingServletand sessiontracking
Servletand sessiontrackingvamsi krishna
 

Similar to Servlet and Servlet Life Cycle (20)

LIFE CYCLE OF SERVLET
LIFE CYCLE OF SERVLETLIFE CYCLE OF SERVLET
LIFE CYCLE OF SERVLET
 
Servlet lifecycle
Servlet  lifecycleServlet  lifecycle
Servlet lifecycle
 
J2ee servlet
J2ee servletJ2ee servlet
J2ee servlet
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
 
IP UNIT III PPT.pptx
 IP UNIT III PPT.pptx IP UNIT III PPT.pptx
IP UNIT III PPT.pptx
 
ajava unit 1.pptx
ajava unit 1.pptxajava unit 1.pptx
ajava unit 1.pptx
 
WEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES ServletWEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES Servlet
 
Major project report
Major project reportMajor project report
Major project report
 
Java Servlet
Java ServletJava Servlet
Java Servlet
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 
Servlet session 2
Servlet   session 2Servlet   session 2
Servlet session 2
 
S E R V L E T S
S E R V L E T SS E R V L E T S
S E R V L E T S
 
J servlets
J servletsJ servlets
J servlets
 
Servlets
ServletsServlets
Servlets
 
Servlets & jdbc
Servlets & jdbcServlets & jdbc
Servlets & jdbc
 
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
 
SevletLifeCycle
SevletLifeCycleSevletLifeCycle
SevletLifeCycle
 
servlet in java
servlet in javaservlet in java
servlet in java
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
Servletand sessiontracking
Servletand sessiontrackingServletand sessiontracking
Servletand sessiontracking
 

More from Dhrumil Panchal

YouTube Cryptocurrency Scam
YouTube Cryptocurrency ScamYouTube Cryptocurrency Scam
YouTube Cryptocurrency Scam
Dhrumil Panchal
 
This and Static Keyword
This and Static KeywordThis and Static Keyword
This and Static Keyword
Dhrumil Panchal
 
Properties and Indexers
Properties and IndexersProperties and Indexers
Properties and Indexers
Dhrumil Panchal
 
Chomsky Normal Form
Chomsky Normal FormChomsky Normal Form
Chomsky Normal Form
Dhrumil Panchal
 
IEEE 802.11 Architecture and Services
IEEE 802.11 Architecture and ServicesIEEE 802.11 Architecture and Services
IEEE 802.11 Architecture and Services
Dhrumil Panchal
 
Key roles for successful analytic project in Data Mining
Key roles for successful analytic project in Data MiningKey roles for successful analytic project in Data Mining
Key roles for successful analytic project in Data Mining
Dhrumil Panchal
 
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dhrumil Panchal
 
Different Software Testing Types and CMM Standard
Different Software Testing Types and CMM StandardDifferent Software Testing Types and CMM Standard
Different Software Testing Types and CMM Standard
Dhrumil Panchal
 
Web Design Issues
Web Design IssuesWeb Design Issues
Web Design Issues
Dhrumil Panchal
 
Toy Interpreter
Toy InterpreterToy Interpreter
Toy Interpreter
Dhrumil Panchal
 
Traditional Problems Associated with Computer Crime
Traditional Problems Associated with Computer CrimeTraditional Problems Associated with Computer Crime
Traditional Problems Associated with Computer Crime
Dhrumil Panchal
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
Dhrumil Panchal
 
Timing Diagram of MVI Instruction of 8085 Microprocessor
Timing Diagram of MVI Instruction of 8085 MicroprocessorTiming Diagram of MVI Instruction of 8085 Microprocessor
Timing Diagram of MVI Instruction of 8085 Microprocessor
Dhrumil Panchal
 
File Management – File Concept, access methods, File types and File Operation
File Management – File Concept, access methods,  File types and File OperationFile Management – File Concept, access methods,  File types and File Operation
File Management – File Concept, access methods, File types and File Operation
Dhrumil Panchal
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal
 
Types of Instruction Format
Types of Instruction FormatTypes of Instruction Format
Types of Instruction Format
Dhrumil Panchal
 
Types of Cables(Guided Media for Transmisson)
Types of Cables(Guided Media for Transmisson)Types of Cables(Guided Media for Transmisson)
Types of Cables(Guided Media for Transmisson)
Dhrumil Panchal
 
Global Service for Mobile Communication
Global Service for Mobile CommunicationGlobal Service for Mobile Communication
Global Service for Mobile Communication
Dhrumil Panchal
 
Denial of Service Attack
Denial of Service AttackDenial of Service Attack
Denial of Service Attack
Dhrumil Panchal
 
Fourier Series
Fourier SeriesFourier Series
Fourier Series
Dhrumil Panchal
 

More from Dhrumil Panchal (20)

YouTube Cryptocurrency Scam
YouTube Cryptocurrency ScamYouTube Cryptocurrency Scam
YouTube Cryptocurrency Scam
 
This and Static Keyword
This and Static KeywordThis and Static Keyword
This and Static Keyword
 
Properties and Indexers
Properties and IndexersProperties and Indexers
Properties and Indexers
 
Chomsky Normal Form
Chomsky Normal FormChomsky Normal Form
Chomsky Normal Form
 
IEEE 802.11 Architecture and Services
IEEE 802.11 Architecture and ServicesIEEE 802.11 Architecture and Services
IEEE 802.11 Architecture and Services
 
Key roles for successful analytic project in Data Mining
Key roles for successful analytic project in Data MiningKey roles for successful analytic project in Data Mining
Key roles for successful analytic project in Data Mining
 
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
 
Different Software Testing Types and CMM Standard
Different Software Testing Types and CMM StandardDifferent Software Testing Types and CMM Standard
Different Software Testing Types and CMM Standard
 
Web Design Issues
Web Design IssuesWeb Design Issues
Web Design Issues
 
Toy Interpreter
Toy InterpreterToy Interpreter
Toy Interpreter
 
Traditional Problems Associated with Computer Crime
Traditional Problems Associated with Computer CrimeTraditional Problems Associated with Computer Crime
Traditional Problems Associated with Computer Crime
 
Breadth First Search (BFS)
Breadth First Search (BFS)Breadth First Search (BFS)
Breadth First Search (BFS)
 
Timing Diagram of MVI Instruction of 8085 Microprocessor
Timing Diagram of MVI Instruction of 8085 MicroprocessorTiming Diagram of MVI Instruction of 8085 Microprocessor
Timing Diagram of MVI Instruction of 8085 Microprocessor
 
File Management – File Concept, access methods, File types and File Operation
File Management – File Concept, access methods,  File types and File OperationFile Management – File Concept, access methods,  File types and File Operation
File Management – File Concept, access methods, File types and File Operation
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Types of Instruction Format
Types of Instruction FormatTypes of Instruction Format
Types of Instruction Format
 
Types of Cables(Guided Media for Transmisson)
Types of Cables(Guided Media for Transmisson)Types of Cables(Guided Media for Transmisson)
Types of Cables(Guided Media for Transmisson)
 
Global Service for Mobile Communication
Global Service for Mobile CommunicationGlobal Service for Mobile Communication
Global Service for Mobile Communication
 
Denial of Service Attack
Denial of Service AttackDenial of Service Attack
Denial of Service Attack
 
Fourier Series
Fourier SeriesFourier Series
Fourier Series
 

Recently uploaded

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
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
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
 
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
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
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
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
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
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 

Recently uploaded (20)

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
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
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
 
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
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
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
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
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
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 

Servlet and Servlet Life Cycle

  • 1. Name: Dhrumil I. Panchal Sem: 6th Semester Subject: Advanced Java Branch: Computer Engineering (B.E.) Year: 2019-20
  • 2. Servlet and Servlet Life Cycle
  • 3.  Servlet  Life Cycle of Servlet
  • 4.  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.
  • 5.  In the life cycle of servlet there are three important methods. These methods are 1. init() 2. service() 3. destroy()
  • 6.
  • 7.  The client enters the URL in the web browser and makes a request. The browser then generates the HTTP request and sends it to the Web server.  Web server maps this request to the corresponding servlet.
  • 8.  The server basically invokes the init() method of servlet. This method is called only when the servlet is loaded in the memory for the first time.  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.  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.  The web container calls the init method only once after creating the servlet instance. The init() method is used to initialize the servlet.
  • 9. public void init(ServletConfig config)throws ServletException { //Servlet Initialization… }  A servlet configuration object used by a servlet container to pass information to a servlet during initialization.
  • 10.  The service() method is the main method to perform the actual task.  The servlet container (i.e. web server) calls the service() method to handle requests coming from the client( browsers) and to write the response back to the client.  Each time the server receives a request for a servlet, the server spawns a new thread and calls service. public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { //Servlet Task }
  • 11.  Finally server unloads the servlet from the memory using the destroy() method.  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 1. database connections, 2. halt background threads, 3. write cookie lists or hit counts to disk, and 4. perform other such cleanup activities.
  • 12.  After the destroy() method is called, the servlet object is marked for garbage collection. public void destroy() { // Finalization code... }
  • 13. import java.io.*; import javax.servlet.*; public class MyServlet1 extends GenericServlet { public void init() throws ServletException { //Initailization Code } public void service(ServletRequest request, ServletResponse response) throws ServletException,IOException { //Servlet code }
  • 15.  Inspiration from Prof. Jayna Shah  Notes of AJAVA  Textbook of AJAVA  Images from Google Images  Some my own Knowledge
  • 16. class Thankyou { public static void main(String args[]) { System.out.println(“Thank You”); } }