In order for a Web server to do more than just display HTML Web pages, many methods have beendevised to let a server run custom programs in response to client requests. However, only a few methods for extending Web servers work the same way on most of the available servers. Another, is the Java Servlet, which is written only in the Java language. A Java Servlet is very similar to a CGI program, except for some major advantages and a few disadvantages. Its single greatest advantage over a CGI program, is that it can be launched once to service many clients.
New requests require only lightweight thread context switches, so processor overhead is much lower.
Unlike CGI, support for Java Servlets is not universal. For example, Microsoft's IIS does not include native support for Java Servlets. I can only imagine that's because of the dispute over Java between Sun and Microsoft, and Microsoft wants to discourage cross-platform development. Java provides strong type checking and memory protection, but usually runs somewhat slower than compiled C code.