Advanced Java (2160707)

BE | Semester-4   Winter-2018 | 20-11-2018

Q4) (b)

What is Servlet? Explain Servlet Life Cycle .

What is 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 .
  • Before Servlet, CGI (Common Gateway Interface) scripting language was popular as a server-side programming language, but there were many disadvantages of this technology.

Servlet Life Cycle

Servlet Life Cycle
(Figure: Servlet Life Cycle)
  1. Servlet class is loaded
    • The classloader 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.
  2. 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.
  3. 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.