• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Servlet » introduction » What is the Servlet container raises the life cycle events in servlet program?
Next →
← Prev

What is the Servlet container raises the life cycle events in servlet program?

By Dinesh Thakur

* Every software and non-software objects life cycle (considering all the operations that are taken place from object birth to object death)

* Our servlet class object life cycle will be managed by servlet container

* Event is an action performed/raised on the object  

                                                                                                                                     

  • Servlet container raises the following life cycle events in the life cycle of our servlet program. They are:
  1. Instantiation Event (raises when servlet container creates our servlet class object)
  2. RequestArrival Event (raises when servlet container takes the browser window generated request)
  3. Destruction Event (raises when servlet container is about to destroy our servlet class object)

When container raises these events on our servlet class object it looks to call certain methods automatically so these methods are called as life cycle methods or container callback methods. They are:

init (ServletConfig cg)

Service (ServletRequest req, ServletResponse res)

Destroy ()

Prototype of servlet life cycle methods

Public void service (ServletRequest req, ServletResponse res) throws ServletException, IOException

Public void init (ServletConfig cg) throws ServletException

Public void destroy ()

* For one life cycle event only one life cycle method will be called by servlet container so init (), service (HttpServletRequest, HttpServletResponse), doXxx () methods are not life cycle methods.

* Servlet container calls init (-) life cycle method for instantiation event.                               

* Servlet container calls service (-,-) life cycle method for RequestArrival event.

* Servlet container calls destroy () life cycle method for destruction event

* The method that is called by underlying container automatically based on the event that is raised on the object is called container callback methods.

* Programmer never calls life cycle methods manually; they will be called by underlying container automatically.

* Servlet API as supplied life cycle methods:

  1. To allow programmer to place his choice logics in the execution of servlet programs.
  2. To supply servlet container created objects to servlet program (also for programmers as parameters of life cycle methods) (like request object, response object, ServletConfig object and etc)

* While overriding super class method in subclass, the method can have same modifier or access modifier

* While overriding protected service () method of predefined HttpServlet class in its subclass we can take either protected or public modifiers for that method.

Public class TestSrc extends HttpServlet

{

      Public void service (here protected method is overridden) (HttpServletRequest,   HttpServletResponse) throws ServletException, IOException

    {

        _______

        _______

        ­­­­_______

    }

}

Service () method-1

Public void service (ServletRequest req, ServletResponse res) throws ServletException, IOException

Service () method-2

Protected void service (HttpServletRequest,   HttpServletResponse) throws ServletException, IOException

* Servlet container is responsible to raise various life cycle events on our servlet class objects so logics placed in life cycle methods are not responsible to raise these events but they are responsible to process these events by executing programmers supplied logic.

Example:- Code which is written in init () life cycle method never creates our servlet class object but programmer places this code as instantiation logic to execute for instantiation event raised by servlet container by creating our servlet class object.

* Life cycle method and its logic are not capable of raising life cycle events on the object but when underlying container raises life cycle events on the objects it automatically calls a relevant life cycle methods.

You’ll also like:

  1. Java Servlet Life Cycle
  2. Life Cycle of JSP
  3. Explain Applet Life Cycle
  4. Software Process and Life Cycle
  5. What is Systems Development Life Cycle?
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Servlet Tutorials

Servlet Tutorials

  • Servlet - Home
  • Servlet - Types
  • Servlet - Advantages
  • Servlet - Container
  • Servlet - API
  • Servlet - Chaining
  • Servlet - Life Cycle
  • Servlet - Developement Way
  • Servlet - Servlet Vs CGI
  • Servlet - Server Side
  • Servlet - HttpServletRequest
  • Servlet - Cookies Advantages
  • Servlet - JDBC Architecture
  • Servlet - HttpServlet
  • Servlet - HttpServletResponse
  • Servlet - Web Technology
  • Servlet - Applet Communication
  • Servlet - Html Communication
  • Servlet - HTTP POST Request
  • Servlet - HTTP GET Request

Other Links

  • Servlet - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW