Home United States USA — software Understanding the Java Servlet Life Cycle – Developer.com

Understanding the Java Servlet Life Cycle – Developer.com

234
0
SHARE

Understand the life cycle of a servlet to understand the intricacies of the low-level functionalities of servlet programming.
Java Servlet is a platform-independent, container-based Web component used to generate dynamic content in a Web page. It is one of the stable technologies to share server-side resources in client-server programming. Because Servlet runs in a multi-threaded environment provided by the container, the life cycle events are completely dependent upon its efficient implementation. Understanding the life cycle of a servlet is the key to understand the intricacies of the low-level functionalities of servlet programming. This article provides a glimpse of this process in a concise manner.
The container , sometimes referred to as a servlet engine , is provided by a Web or an application server within which servlets run. Similar to simple Java programming, servlets are Java classes compiled to bytecode. These bytecodes are loaded dynamically into a Java technology-enabled Web server. A servlet container is often built into the server by default or sometimes provided as an add-on component via the server’s native extension. The servlet classes generally interact with the server via an HTTP request/response mechanism implemented by the servlet engine. The primary function of the container is to contain servlet classes and manage their life cycle. Apart from supporting HTTP protocol, the servlet container also supports request/response based protocols, such as HTTPS, for a more secure network interaction.
Typically, a servlet goes through the following sequence of events:
Figure 1: Control passing between the client and server
The life cycle begins as soon as it is called by the Web sever to load into the container. Grossly, it has a three-phase life: instantiation and initialization , service , and destruction.
Figure 2: The life cycle
In the initialization phase, the servlet container starts by locating servlet classes either in the local file system or from a remote location.

Continue reading...