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()
Servlet and Servlet Life Cycle
 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

PDF
PPTX
Exceptions in Java
PDF
Remote Method Invocation (RMI)
PPS
Java rmi
PPTX
servlet in java
PPT
PPTX
CSharp Presentation
Exceptions in Java
Remote Method Invocation (RMI)
Java rmi
servlet in java
CSharp Presentation

What's hot (20)

PPT
Cookies in servlet
PPTX
Java - Collections framework
PPTX
JAVA AWT
PPS
Wrapper class
PPTX
LIFE CYCLE OF SERVLET
PPTX
Java Server Pages(jsp)
PPTX
Java RMI
PPTX
PPTX
Multithreading in java
PPTX
PPTX
Enterprise java unit-2_chapter-1
PPTX
Validation Controls in asp.net
PPSX
JDBC: java DataBase connectivity
PPTX
ArrayList in JAVA
PPT
Uml class-diagram
PPTX
Asp.NET Validation controls
PPT
Java Networking
PDF
Distributed Operating System_4
PPTX
Multithreading in java
Cookies in servlet
Java - Collections framework
JAVA AWT
Wrapper class
LIFE CYCLE OF SERVLET
Java Server Pages(jsp)
Java RMI
Multithreading in java
Enterprise java unit-2_chapter-1
Validation Controls in asp.net
JDBC: java DataBase connectivity
ArrayList in JAVA
Uml class-diagram
Asp.NET Validation controls
Java Networking
Distributed Operating System_4
Multithreading in java
Ad

Similar to Servlet and Servlet Life Cycle (20)

PDF
Servlet Life Cycle & Generic Servlet
PPT
Servlet lifecycle
PPTX
Servlet session 2
PPT
S E R V L E T S
RTF
Servlet lifecycle
PPTX
Introduction to Servlet.pptx
PPTX
SevletLifeCycle
PPTX
Servlet_Life_cycle has details about the phases.pptx
PPTX
J servlets
PPTX
Enterprise java unit-1_chapter-3
PPT
Servlet ppt by vikas jagtap
PPTX
ajava unit 1.pptx
PDF
Servlet and servlet life cycle
PDF
Servlet
PDF
java servlet and servlet programming
PPTX
JAVA SERVLETS acts as a middle layer between a request coming from a web brow...
PPTX
SERVLET in web technolgy engineering.pptx
PPTX
java Servlet_Life_Cycle_Notes with basic level
PPTX
Java servlets
PDF
servlet_lifecycle.pdf
Servlet Life Cycle & Generic Servlet
Servlet lifecycle
Servlet session 2
S E R V L E T S
Servlet lifecycle
Introduction to Servlet.pptx
SevletLifeCycle
Servlet_Life_cycle has details about the phases.pptx
J servlets
Enterprise java unit-1_chapter-3
Servlet ppt by vikas jagtap
ajava unit 1.pptx
Servlet and servlet life cycle
Servlet
java servlet and servlet programming
JAVA SERVLETS acts as a middle layer between a request coming from a web brow...
SERVLET in web technolgy engineering.pptx
java Servlet_Life_Cycle_Notes with basic level
Java servlets
servlet_lifecycle.pdf
Ad

More from Dhrumil Panchal (20)

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

Recently uploaded (20)

PDF
Design Guidelines and solutions for Plastics parts
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
Current and future trends in Computer Vision.pptx
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
PPTX
Information Storage and Retrieval Techniques Unit III
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
Module 8- Technological and Communication Skills.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Software Engineering and software moduleing
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Visual Aids for Exploratory Data Analysis.pdf
Design Guidelines and solutions for Plastics parts
Safety Seminar civil to be ensured for safe working.
Current and future trends in Computer Vision.pptx
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
III.4.1.2_The_Space_Environment.p pdffdf
Fundamentals of safety and accident prevention -final (1).pptx
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
Information Storage and Retrieval Techniques Unit III
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Module 8- Technological and Communication Skills.pptx
R24 SURVEYING LAB MANUAL for civil enggi
Software Engineering and software moduleing
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
Exploratory_Data_Analysis_Fundamentals.pdf
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Visual Aids for Exploratory Data Analysis.pdf

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()
  • 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”); } }