CGI means common gateway interface used for server side programming.
Servlet has many advantages over CGI. These are,
1) Each request in servlet is processed by creating separate thread to run service method, i.e.., for each request only service method is executed, not initialized every time.
For each request in CGI the server creates a separate process to execute, which is overhead on server. And process will terminate after processing request. Consumes time and memory.
2)Init, Service, Destroy Life Cycle in Servlet but CGI Passes request to corresponding script.
3)Servlet is powerful as it has implicit support of Java Language itself, but in CGI Should be done explicitly.
4)Servlets are portable among operating systems and among servers, but CGI is not.
5)In Servlet built-in session handling feature but in CGI it should be done explicitely.