10.2. How Servlets Work

When a client sends a request to a servlet-enabled server that invokes a servlet, the server first checks to see if the servlet is loaded. If it is not, the servlet class is loaded and a new instance is created. The servlet is then initialized by a call to its init() method, which can contain startup code similar to the init() method of an applet. Once the servlet is ready, a call to its service() method is made. This lifecycle is relatively simple, as shown in Figure 10-1. Figure 10-2 shows the process by which a servlet is loaded, initialized, and made ready to service client requests in a servlet-enabled Web server.

Figure 10-1. Servlet life cycle
Figure 10-2. Servlet instantiation, initialization, and processing of ...

Get Java™ Network Programming and Distributed Computing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.