Why Use Servlets?
Servlets have a variety of enhancements over plain CGI. The most fundamental advantage of Servlets is that they are tightly coupled to the Web Server. If you recall from the diagram above, CGI scripts are typically launched as a separate process by the web server whose lifetime exists only during the particular user request. It turns out that the CGI model is extremely inefficient and slow especially with interpreted languages such as Perl or Java. First, operating systems typically incur some overhead in simply launching another process. When you think about it, an operating system really has to do quite a bit. It has to: • allocate memory for the process • copy information about the environment that the parent process was running in so that there is a security context • and the web server (parent process) must be constantly aware of the child process in order to send the CGI output back to the user’s web browser. Second, an interpreted language typically has to load an entire program