UNIT 2 IWT By : Dr.
Shilpa Bahl
COMMON GATEWAY INTERFACE
The Common Gateway Interface is the standard interface between the
WWW and the external program.
CGI is the mechanism that is part of the Hypertext Transport Protocol
(HTTP). One of the examples of CGI flow is the Web browsers send the
forms data to the backend server, and CGI connects to the application
program on the web-server and the program response to the web
browser.
When a user browses the web with a request using a URL to the server,
the server passes the URL. The filename is searched which is kept in a
pre-configured directory called CGI Directory and displays the file or error
message back to the user.
The technology allows web browsers to submit forms and connect to
programs over a web server.
The best way web browsers send forms and simply to connect to
programs on the server.
To get an example, when you fill-up the form and submit the form
applying click the submit button, and it goes, what are the results from
this level is CGI.
UNDERSTANDING COMMON
GATEWAY INTERFACE
•The web browser submits the information to
the server. The server moves that data
through to an application (CGI Program). The
application responds, and it goes back up the
chain, back to your web browser as well as
your web browser can be some sort of result
and possibly something occurs around the
backend such as a database thing or sending
an email or perhaps similar to that.
•CGI is used for simple interactive applications.
•More complicated applications like Google
Maps or Gmail use another technology
called Ajax, which sometimes actually uses
CGI on the backend to communicate with the
applications on their server.
CONTD….
•CGI applications can be written in any programming language.
The most common ones are languages like Perl, PHP and Python,
and things like that tend to be simple languages. For this reason,
CGI applications are often called CGI scripts because they tend to
be scripting languages, and they are often called CGI scripts.
•They can be written in any programming languages like ASP or
Java, or even C++ can be used, but it is important to note that CGI
application runs in the server.
CGI FEATURES
•The CGI is a simple interactive shell script or
application.
•CGI executes with a well-defined set of
instructions.
•CGI scripts are mostly written in Perl, C, etc. The
applications can be written in
Java, Python, PERL, C++, C, etc. any language like
•HTML can also be used for interfaces where CGL is
a technology.
•CGI is easier than Java when advanced functions
are performed.
•CGI includes reusable pieces of code.
•A basic and simple way for the user to request the
server to get a response back.
ADVANTAGES OF CGI:
•Quick implementation: CGI can be a quick and straightforward
method for implementing simple web-based tasks, such as
form processing or data manipulation.
•Easy to use existing code: There is a large existing code base
of CGI scripts, especially in Perl, which can be readily used or
customized for specific requirements.
•Well-defined and supported standard: CGI is a widely accepted
standard in web development, ensuring compatibility across
different systems and platforms.
•CGI-based counters and CGI code to perform simple tasks are
available in plenty.
DISADVANTAGES OF CGI:
•Overhead in page loads: Each page load in CGI incurs overhead by having to
load the script into memory, which can impact performance, especially in high-
traffic websites. For example, if a website receives a large number of requests,
the overhead of loading the CGI script for each request can result in slower
response times.
•Limited caching capabilities: CGI scripts do not easily allow for caching of data
in memory between page loads, which can affect performance and scalability.
•Security: Since CGI scripts are executed on the server, there is always a risk of
security vulnerabilities. For example, if the script does not properly validate
user input, it may be vulnerable to SQL injection attacks.
•Scalability: CGI is not well-suited for handling large volumes of traffic or
requests. As the number of requests increases, the performance of the server
may suffer, leading to slower response times or even crashes.
SERVER SPECIFIC API
Server-side APIs act as intermediaries between client applications and backend systems,
ensuring secure, scalable, and efficient data handling. Server-side APIs are a type of
interface that resides on the server, acting as a middle layer between the client (such as
a mobile app or web browser) and the server where the data resides. These APIs process
requests from the client, fetch or modify the required data from the database, and then
return the processed response back to the client.In simpler terms, server-side APIs are
responsible for:
•Managing requests from the front end (user interface).
•Querying databases or external services to fetch data.
•Applying business logic to process the data.
•Sending structured responses back to the client.
For example, in a React Native app for eCommerce, the client (app) sends a request to
the server-side API to fetch product details. The API retrieves the data from the database,
NEED FOR SERVER SIDE API’S
# Data Security and Privacy
Server-side APIs keep sensitive operations, such as authentication, data validation, and
database interactions, secure by keeping them on the server. Unlike client-side APIs,
which can be exposed to users and malicious actors, server-side APIs are protected by
server-level security protocols.
# Efficient Data Processing
Server-side APIs allow complex data processing and business logic to be handled on the
server, reducing the load on the client device. This is particularly important for mobile
apps where hardware resources are limited.
# Scalability
Server-side APIs are built to handle high volumes of requests and can be scaled as the
user base grows. They work efficiently with server clusters and load balancers to
distribute workloads, ensuring smooth performance even during peak traffic.
# Cross-Platform Support
Server-side APIs provide a unified backend that can serve multiple
platforms, including mobile apps, web apps, and IoT devices. This
simplifies development and maintenance by reducing redundant
work across platforms.
# Real-Time Updates
Server-side APIs facilitate real-time updates, such as notifications,
chat messages, or live data feeds. This enhances the
responsiveness of applications, providing users with a dynamic
experience.
INTRODUCTION TO JAVA SERVLETS
Java Servlet is a Java program that runs on a Java-enabled
web server or application server. It handles client requests,
processes them, and generates responses dynamically. Servlets
are the backbone of many server-side Java applications due to
their efficiency and scalability.
•Servlets work on the server side.
•Servlets are capable of handling complex requests obtained
from the web server.
•Generate dynamic responses efficiently.
WHY CHOOSE JAVA SERVLET OVER OTHER
TECHNOLOGIES
Dynamic web content requires server-side technologies. While there are many options, Java Servlet stand
out due to their advantages over alternatives like Common Gateway Interface (CGI)
Limitations of CGI:
• Process Overhead: CGI creates and destroys a process for every client request, leading to high resource
consumption.
• Scalability Issues: Poor performance with increased client requests.
Benefits of Java Servlets:
• Performance: Faster execution as Servlets do not create new processes for each request.
• Portability: Write-once, run-anywhere feature of Java..
• Memory: Single instance handles multiple requests.
• Integration: Easily integrates with databases using JDBC.
• Security: Inherits robust security features from web servers.
JAVA SERVLETS ARCHITECTURE
Execution of Java Servlets
Execution of Servlets basically involves Six basic
steps:
• The Clients send the request to the Web Server.
• The Web Server receives the request.
• The Web Server passes the request to the
corresponding servlet.
• The Servlet processes the request and
generates the response in the form of output.
• The Servlet sends the response back to the
webserver.
• The Web Server sends the response back to the
client and the client browser displays it on the
screen.
COMPARISION