Showing posts with label Servlets Vs CGI. Show all posts
Showing posts with label Servlets Vs CGI. Show all posts

Monday, 14 July 2014

Servlets Vs CGI

Servlets Vs CGI 

Servlet CGI (Common Gateway Interface)

Servlets can link directly to the Web server. CGI cannot directly link to Web server.
Servlets can share data among each other. CGI does not provide sharing property.
Servlets can perform session tracking and caching of previous computations. CGI cannot perform session tracking and caching of previous computations.
Servlets are portable. CGI is not portable.
In Servlets, the Java Virtual Machine stays up, and each request is handled by a lightweight Java thread. In CGI, each request is handled by a heavyweight operating system process.
Servlets automatically parse and decode the HTML form data. CGI cannot automatically parse and decode the HTML form data.
Servlets can read and set HTTP headers, handle cookies, tracking sessions. CGI cannot read and set HTTP headers, handle cookies, tracking sessions.
Servlets is inexpensive than CGI. CGI is more expensive than Servlets



Advantages of servlets over CGI
  • Request is run in a separate thread,so faster than CGIs
  • Scalable,can serve many more requests,
  • Robust and Object Oriented.
  • Can be written in Java Programming language.
  • Platform independent.
  • Access to Logging Capabilities.
  • Error handling and Security.

CGI -  
  • CGI creates a new process for each request Whereas Servlet creates a thread for each request and services the request in that thread.
  • For each process created by CGI the process is assinged seperate address space.SO there is memory overload on the server.Whereas for every thread created by the servlet no seperate address space is created all threads operate in the same parent process address space.so there is no memory overlaod.
  • CGI is not based on pooling Whereas servlet are container managed pooled objects.