Life cycle of servlet

The web container handles the life cycle  of a servlet:

1- Servlet class is loaded:

Java classloader load Servlet class file.
when the web container receives the first request for the servlet, the classloader loads the class file.

2- Servlet instance is created:

When class loading is done, after that servlet instance is created.
Note-- Servlet instance is created only once in the servlet life cycle.

3- init method execution:

After the successful creation of a servlet instance, the web container invokes the init method in the picture.

3- service method execution:

every time when a client request something service method will execute if the servlet instance is not created yet then the first three-step follow by web container else only service method will execute.

4- destroy method execution

No comments:

Post a Comment