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 |
When jsessionid is created?
What does the term localization refer to?
Can we fetch the attributes related to a servlet on a different servlet?
What advantages do servlets have over CGI programs?
Differentiate between get and post?
Which is the methods of generated servlet?
Can you send the mail from a servlet ,if yes tell how?
How to debug a servlet?
How does java thread pool work?
Can you send an authentication error from a servlet?
What is Generic Servlet and how it is different from Http Servlet?
What are the types of ServletEngines?