what is the advantage of using Servlets over CGI programming?
Answers were Sorted based on User's Feedback
Answer / mdsha_asiya
The problem with CGI script is that your server must
restart the CGI script every time a new request is
issued.This means every time a client communicates,your
server needs to begin a new proccess .starting and stopping
processes are expensive operions.
The difference between servlet and CGI scritpt is that CGI
script must be restarted every request where as servlets
are pooled and reused over and over again to service many
requests.This means you don't have to restart a process
every time client request comes over the network.
After servlet is loaded,to handle client request it simply
creates a thread and runs service() of servlet.
servlets are more efficient,powerful,portable,inexpensive
and convinent.
Is This Answer Correct ? | 14 Yes | 2 No |
Answer / janet
Servlets are only instantiated when the client first
accesses the program. All subsequent accesses are done to
that instance.This keeps the response time of servlets lower
than that of CGI programs, which must be run once per
hit.also because servlet is instantiated only once,all
accesses are put through that one object. This helps in
maintaining objects like internal connection,pooling or user
session tracking and lots of other features.
Is This Answer Correct ? | 11 Yes | 0 No |
Answer / sandeep m
CGI programs need separate process to process a request.
For which CGI object has to be created and destroyed for
each request or else pool of processes can be maintained by
server and for each request a process is assigned by server
which will be returned back to server after request
processing.
Servlets use Threads. Due to which single Servlet object is
created. Whenever a request is received by server a new
thread is created and the thread uses the existing Servlet
instance.
Advantage is process creation is heavy weight. Threads are
light weight. Burden of creating and destroying processes
is reduced or else maintaining process objects in pool is
reduced. Any number of requests can be served with not much
burden on server
Is This Answer Correct ? | 4 Yes | 1 No |
Answer / ravat
There is only one main difference between CGI and Servlet that CGI is not that much efficient as servlets ,because Wen each time request cames to CGI it ll start from first i.e loading,instantiation and ll consume more time but in the case of Servlet only once server is loaded and instance is created and it is reused to other request and wenever the new request cames just it ll make use of same object
Is This Answer Correct ? | 3 Yes | 3 No |
What is setattribute in servlet?
can i modify the data which are generated by the servlet
Whether we can get deadlock situation in servlets?
Why the container loads server at the application startup and how?
Name the servers that can be used to develope and deploy Servlets?
How do you invoke a servelt?
What are different methods of session management in servlets?
How do you pass the data from one servlet to another servlet?
How do cookies work in servlets?
What is the purpose of inter-servlet communication?
What is meant by Servlet? What are the parameters of service method?
What are the life cycle methods of the servlet?