Servlets are Java classes that extend the functionality of a Web server by dynamically generating Web pages. A run-time environment known as a servlet engine manages servlet loading and unloading, and works with the Web server to direct requests to servlets and to send output back to Web clients. Since their introduction in 1997, servlets have become the dominant environment for server-side Java programming and a widely used portal into application servers. They offer several key advantages:
Performance Older technologies such as the Common Gateway Interface (CGI) typically start a new process to handle each incoming request. In the days when the Web was primarily a repository for academic and scientific research, there wasn’t very much traffic and this approach worked well. Servlets, by contrast, is loaded when first requested, and stay in memory indefinitely. The servlet engine loads a single instance of the servlet class and dispatches requests to it using a pool of available threads. The resulting performance improvement is considerable.
Simplicity Client-side Java applets run in a virtual machine provided by the Web browser. This introduces compatibility issues that increase complexity and limit the functionality that applets can provide. Servlets simplify this situation considerably because they run in a virtual machine in a controlled server environment and require only basic HTTP to communicate with their clients. No special client software is required, even with older browsers.
HTTP Sessions Although HTTP servers have no built-in capability to remember details of a previous request from the same client, the Servlet API provides an HttpSession class that overcomes this limitation.
Access to Java Technology Servlets, being Java applications, have direct access to the full range of Java features, such as threading, network access, and database connectivity. JSP pages, which are automatically translated into servlets, inherit all these advantages.
Source :- JSP: The Complete Reference By Phil Hanna