How web technology and CGI works ??
Whenever a User clicks on a link or types in a URL at the browser, the web browser formats the request and sends it to the server. Browser is a software that knows how to communicate with the Server.
Server accepts the request and finds the requested page. Then, server formats the response and sends the response back to the client, that is the browser.
Once the web browser gets the response, it renders the content for displaying to the user.
A web application is any software application whose services can be accessed via the Web. The communication between client and server happens using the HTTP protocol.
To access a website, you use a URL (Uniform Resource Locator).
Static Vs Dynamic Web applications :
Static web application – non interactive web application. Same information returned to all client requests.
Dynamic web applications – uses server side processing and generate web site content on the fly. Uses web container for server side processing.
Why we require Servlets ?
Web servers typically load static web pages whenever the client sends a request to the web server, the server accepts the request, finds the resource, and returns the relevant resource to the client. Sometimes that resource is an HTML page. Sometimes it might be a picture or a song file or even a PDF document. Static pages just sit there in a directory. The server finds it and hands it back to the client. The processing of the page happens at the client, that is, web browser. – Static Web Application.
With Static web application, every client will see the same information, but sometimes we need more than that. We need to perform some kind of computations at the server side like interacting with the database or platforms or processing some kind of business logic.
Dynamic web applications – uses server side processing and generate web site content on the fly. But the web server application can’t do those computations. It requires another helper application on the server, which can handle this task.
Web Server uses web container for server side processing. The web server will take care of getting the request to the right helper app. It will also take that application’s response and send it back to the client.
The first technology which was used for building the helper application is CGI, which stands for Common Gateway Interface. CGI programs can be written using PERL scripts, C and Python.
How a CGI program works ??
- Whenever the user clicks on a link that has a URL to a CGI program, instead of a static page, the web server application identifies that the request is for a helper program so the web server launches and runs the helper program.
- The web server app also sends the parameters from a GET or POST request to the helper program.
- Once the helper app receives the request, it constructs a brand-new page and sends the HTML back to the server. As far as the web server is concerned, the HTML from the helper app is considered as a static page.
- Once the server receives the HTML content, the helper application will shut down, and the client receives an HTML page as a part of its dynamic content.
But whenever we use the CGI programs, performance-related issues will arise because the server has to launch a heavyweight process for each and every request for the resource.
Further, there’s no possibility for a CGI program to keep database connections open over a number of requests. For each request a new database connection must be established, which leads to a significant performance cost in database-centric applications.
The answer to the CGI technology limitations are Java Servlets.