The Servlet API consists of two packages,
javax is left over from an earlier stage of
Java package naming conventions. As mentioned (and as indicated by the
fact that this chapter appears in Part I of this book), servlets are
a standard part of J2EE.
When a client makes a request involving a servlet, the server loads and executes the appropriate Java classes. Those classes generate content, and the server sends the content back to the client. In most cases, the client is a web browser, the server is a web server, and the servlet returns standard HTML. From the web browser’s perspective, this isn’t any different from requesting a page generated by a CGI script or, indeed, a static HTML file. On the server side, however, there is
Figure 3-1. The servlet lifecycle
an important difference: persistence. Instead of shutting down at the end of each request, the servlet can remain loaded, ready to handle subsequent requests. Figure 3-1 shows how this all fits together.
The request processing time for a servlet can vary, but it is typically quite fast when compared to a similar CGI program. The real performance advantage of a servlet is that you incur most of the startup overhead only once. Most of the I/O-intensive resources (such as database connection pools) your application will need can be created by the servlet ...