What is CGI(Common Gateway Interface)?

CGI is actually an external application that is written by using any of the programming languages like C or C++ and this is responsible for processing client requests and generating dynamic content. 

In CGI application, when a client makes a request to access dynamic Web pages, the Web server performs the following operations:  

  • It first locates the requested web page i.e the required CGI application using URL.
  • It then creates a new process to service the client’s request.
  • Invokes the CGI application within the process and passes the request information to the application.
  • Collects the response from the CGI application.
  • Destroys the process, prepares the HTTP response, and sends it to the client.

So, in CGI server has to create and destroy the process for every request. It’s easy to understand that this approach is applicable for handling few clients but as the number of clients increases, the workload on the server increases and so the time is taken to process requests increases.  

Introduction to Java Servlets

Today, we all are aware of the need to create dynamic web pages i.e. the ones that can change the site contents according to the time or can generate the content according to the request received from the client. If you like coding in Java, then you will be happy to know that using Java there also exists a way to generate dynamic web pages and that way is Java Servlet. But before we move forward with our topic let’s first understand the need for server-side extensions. 

Similar Reads

What is Java Servlet?

Java Servlets are the Java programs that run on the Java-enabled web server or application server. They are used to handle the request obtained from the web server, process the request, produce the response, and then send a response back to the web server....

Java Servlets Architecture

Servlet Architecture can be depicted from the image itself as provided below as follows:...

What is CGI(Common Gateway Interface)?

CGI is actually an external application that is written by using any of the programming languages like C or C++ and this is responsible for processing client requests and generating dynamic content....

Difference between Java Servlets and CGI

Servlet CGI (Common Gateway Interface) Servlets are portable and efficient. CGI is not portable. In Servlets, sharing data is possible. In CGI, sharing data is not possible. Servlets can directly communicate with the webserver. CGI cannot directly communicate with the webserver. Servlets are less expensive than CGI. CGI is more expensive than Servlets. Servlets can handle the cookies. CGI cannot handle the cookies....

Servlets APIs

Servlets are built from two packages:...

The Servlet Container

Servlet container, also known as Servlet engine, is an integrated set of objects that provide a run time environment for Java Servlet components. In simple words, it is a system that manages Java Servlet components on top of the Web server to handle the Web client requests....

Conclusion

Java Servlets are crucial components for defining business logic and handling complex web requests. These components promote the dynamic development of a web site and has a lot of potential to change the application dynamics. Here are some of the key features we learn in this article:...

FAQs on Java Servlet

Q1. What is the Lifecycle of Java Servlet?...