Discuss the life cycle of JSP.
A JSP (JavaServer Pages) page services requests like a servlet. Therefore, the life cycle and many of the abilities of JSP pages (particular in the dynamic aspects) are determined through Java Servlet technology Servlet Life Cycle
The life cycle of a servlet is controlled through the container wherein the servlet has been deployed. While a request is mapped to a servlet, so the container performs the steps as follows.
1. If an example of the servlet does not exist, the Web container
a. Loads the servlet class.
b. Creates an example of the servlet class.
c. Establishes the servlet instance through calling the init method.
2. Raise the service method, passing a request and object response.
If the container requires to remove the servlet, this finalizes the servlet through calling the servlet's destroy method.
Handling Servlet Life-Cycle Events
You can observe and react to events in a servlet's life cycle through defining listener objects that methods find invoked when life cycle events arise. To utilize these listener objects, you should define the listener class.