Common
Gateway Interface
To
understand the power of Servlets, we need to under stand CGI. CGI is
a standard method used to generate dynamic content on web pages and
web applications. CGI is the first attempt to provide dynamic content
to the users.
CGI
is the part of the Web server that can communicate with other
programs running on the server. With CGI, the Web server call a
program, while passing user-specific data to the program (such as
form data, login data etc., ). The program then processes that data
and the server passes the program's response back to the Web browser.
CGI
Vs Servlets
- The first Advantage of servlets over CGI is, Servlets are platform-independent, if you have JVM in your machine, then you can run servlet. Even if you migrate to other operating systems also, same compiled servlet code works. But this is not the case with CGI, it is platform dependent you need to recompile all the programs, to migrate.
- In Servlets each request is handled by a lightweight Java thread. Where as In CGI, each request is handled by a heavyweight operating system process. Obviously CGI kills the performance.
- The first time a Servlet is requested, it is loaded into memory and cached. From then on, the same Servlet instance is used, with different requests being handled by different threads. Where as for every new request, new process is created in CGI.
- Servlets can access large sets of APIs provided by Java Platform.
No comments:
Post a Comment