This document provides an introduction and comparison of Java servlets and CGI (Common Gateway Interface) for creating dynamic web applications. Servlets use Java to build applications that reside on the web server and can generate dynamic web pages. CGI allows using programs on the server to process data and generate dynamic content, but programs must be written in a native language like C++. Servlets offer advantages like portability, ability to share data between requests, and better performance due to using threads instead of processes to handle requests.
JAVA SERVLETS ANDCGI
Presented by
M.LAVANYA
M.sc(CS & IT)
Nadar Saraswathi college of arts & science,
Theni.
2.
INTRODUCTION TO SERVLETS
•Servlet Technology is used to create web applications.
• Servlet technology uses Java language to create web
applications.
• Web applications are helper applications that resides at web
server and build dynamic web pages.
• A dynamic page could be anything like a page that randomly
chooses picture to display or even a page that displays the
current time.
3.
As Servlet Technologyuses Java, web applications made using
Servlet are Secured, Scalable and Robust.
4.
INTRODUCTION OF CGI
•CGI (Common Gateway Interface) is used to provide dynamic
content to the user.
• CGI is used to execute a program that resides in the server to
process data or access databases to produce the relevant
dynamic content.
• Programs that resides in server can be written in native
operating system such as C++.
DIFFERENT OF CGI
ServletCGI (Common Gateway Interface)
Servlets are portable CGI is not portable.
In Servlets each request is handled by
lightweight Java Thread
IN CGI each request is handled by heavy
weight OS process
In Servlets, Data sharing is possible In CGI, data sharing is not available.
Servlets can link directly to the Web
server
CGI cannot directly link to Web server.
Session tracking and caching of previous
computations can be performed
Session tracking and caching of previous
computations cannot be performed
7.
Automatic parsing anddecoding of
HTML form data can be performed.
Automatic parsing and decoding of
HTML form data cannot be performed.
Servlets can read and Set HTTP Headers CGI cannot read and Set HTTP Headers
Servlets can handle cookies CGI cannot handle cookies
Servlets can track sessions CGI cannot track sessions
Servlets is inexpensive than CGI CGI is more expensive than Servlets
8.
CGI (COMMON GATEWAYINTERFACE)
• Before Servlets, CGI(Common Gateway Interface)
programming was used to create web applications. Here's how
a CGI program works :
• User clicks a link that has URL to a dynamic page instead of a
static page.
9.
• The URLdecides which CGI program to execute.
• Web Servers run the CGI program in separate OS shell. The
shell includes OS environment and the process to execute code
of the CGI program.
• The CGI response is sent back to the Web Server, which wraps
the response in an HTTP response and send it back to the web
browser.
DRAWBACKS OF CGIPROGRAMS
• High response time because CGI programs execute in their
own OS shell.
• CGI is not scalable.
• CGI programs are not always secure or object-oriented.
• It is Platform dependent.
12.
SERVLETS
• CGI programsare used to execute programs written inside the
native language. But in Servlet all the programs are compiled
into the Java byte code which is then run in the Java virtual
machine.
• In Servlet, All the requests coming from the Client are
processed with the threads instead of the OS process.