Difference Between Servlet and CGI in Java
Contents
CGI and Servlet Difference
- The Key Difference Between Servlet and CGI is that Servlets are thread based and CGI is process based work.
- CGI and Servlet Both are server-side technologies
Servlet vs CGI Comparison Chart

Servlet | CGI |
---|---|
Servlet is written in java class & its runs in JVM. | The CGI programs are written in native OS. |
Servlet creates a new thread to process each request. | Servlet creates a new thread to process each request. |
Servlets are Server-based java program that runs on the webserver. | CGI describes as Common Gateway Interface that can’t directly run on the webserver. |
The main purpose of servlets is to add up the functionality to a web server. | The CGI is a language-independent interface that allows a server to start an external process. |
Servlets stay in the memory while serving the requests. | A CGI program needs to be loaded and started on each CGI request. |
Servlets are useful to read and set the HTTP servers. | CGI is not able to read the HTTP servers. |
Servlets are plateform independent. | CGI are plateform dependent. |
Servlets are more secure because it uses java programming. | CGI is less secure. |
Servlet is useful for Data sharing. | CGI is not useful for data sharing. |
Servlet is faster. | CGI is slower. |
Servlet is more Portable. | CGI is not portable. |