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
(Figure: Servlet Life Cycle)
-
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.
-
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.