Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what is diff between a servlet and a CGI  RSS feed

 
Raja Siva Ganesh Panuganti
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to know the main defiiernce between these two and the advatages of servlet over CGI
Can we use CGI in java aplications
plzzz iam very much curious abt the working of both servlet and CGI and their pros and cons


Thnaks in advance
 
Arun Somasundaram
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you take CGI the CGI program on the server is executed for every request i.e, the CGI program is loaded for every request into the servers memory.

When coming to servlets it is loaded only once.

i.e, it has three life cycle methods

1.)init()
2.)service()
3.)destroy()

Every servlet is initialized only once,i.e the init() is executed only once.

The logic is coded in the service method,which services the client's request.Each request is accepted and a thread is created for each request.

for example

If 5 clients accesses a servlet called Test simultaneously

5 service() methods are executed one for each client i.e as I said a thread is created for each client's request.

After servicing all the clients , the servlet is ready to serve any number of clients . It is not destroyed like CGI's after servicing each client.

The destroy() method for a particluar servlet is invoked when a server is shutdowned and the servlet is destroyed.This destroy() method is also executed once for each servlet.
 
Raja Siva Ganesh Panuganti
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
thats why we use IO exception in servelet service()
thank you very much
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!