Servlets are programs that run within the context of a server, analogous to applets that run within the context of a browser. They can be used to implement an arbitrary service easily and efficiently. Easily, since they the programmer may take advantage of the support provided by the Java Web Server, such as parsing HTTP requests and handling connections to Web clients. Efficiently, since servlets run as separate light weight threads of the Java Server process rather than as separate heavy weight processes; thus, they load and execute much faster than CGI programs.
Servlets are part of a larger Java Server Archiecture. That architecture was first implemented in a server built by Sun that was called Jeeves, later renamed the Java Web Server. Developers of other Web server are incorporating the key interfaces in the architecture into their products so that support for servlets is not limited to just Sun's Java Server.
In the discussion that follow, we will begin by looking at several concepts basic to servlets. We will then look at the mechanics of writing, compiling, and running servlets. Next, we will look at simple transaction servlets that behave like CGI programs. Finally, we will consider more complex servlets that support independent connections with clients and multiple interactions.
Basic Concepts
Two basic concepts are discussed: the "rhythm of interaction" that is required for a servlet to be invoked and the class hierarchy for servlets.
Mechanics
The steps necessary to compile, store, and run a servlet are discussed.
Example Servlets
References
References useful for this discussion include the following::