Servlet Technology |
Active Web |
A Servlet takes its name from the modules of Java code that execute in an application server and provide answers to client requests. Although Servlet technology is commonly linked with the Hypertext Transfer Protocol (HTTP) they are in fact protocol independent. However, in practice, most are tied to HTTP.
A Servlet is typically used:
For processing and/or storing data that has been submitted by an HTML form from a client browser.
They also provide dynamically generated content typically by using elements of the request to access some form of database and to provide results to the requesting client.
Maintaining some type of state information that the stateless HTTP does not support. For example the contents of a shopping cart.
A Servlet is written in Java and processes client requests. They are an exact match for the existing Active Web model of receive request, process and generate response.
In days gone by the traditional mechanism of adding dynamic processing to a web server was with the Common Gateway Interface (CGI). It is a language-independent interface that allows a web server to start an external process which has the request received by the web server presented to it in a standard way through environment variables, its command line and standard input stream. The CGI process then writes its dynamically-generated output to its standard output stream. Each request of the web server requires its own CGI process. CGI processes can typically be written in any language.
Servlet technology has many advantages over this architecture:
They do not run in a separate process and so are not subject to the overhead of starting a new CGI process for each request.
A Servlet is typically multi-threaded and there is typically only one instance of a Servlet object processing all the requests concurrently in different threads. This dramatically reduces the memory overhead and gives the added benefit of making session information persistence easier.
Servlet containers can also execute a Servlet in a secure environment known as a Sandbox, thereby securing the rest of the application server from a potentially harmful Servlet.
Topic ID: 150127