File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes CGI and servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "CGI and servlets" Watch "CGI and servlets" New topic
Author

CGI and servlets

ramchander yshetti
Ranch Hand

Joined: Apr 22, 2006
Posts: 97
hai,

what is CGI(according to my knowledge CGI is process based)
and (Servlets are Thread based) is it write
please clear me
and give me your comment.

bye
Amit Kumargupta
Ranch Hand

Joined: Apr 13, 2007
Posts: 54
servlets are excuted as threads and servlets are language independent.
servlet is used to handle request and response .Multiple concurrent request accessing the service method of the same servlet instance,for eg:when a client give a request one instance is created and receive a response from the server,the same client may give a request but it can access the same instance so,it can initialize only once and it cannot create a multiple instance for single client.
so,if we avoid the multiple instance use servlets.

CGI are excuted as process and CGI are language dependent
but for CGI each and every request it can create a new process , so every time it can receive a new request it can create a multiple instance for multiple clients,so it can take more memory address space.
and so servlet is more advantage than CGI.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41148
    
  45
I think Amit has it the wrong way around. Servlets are language-dependent - I'm not aware of any server implementation that uses the term "servlet" except Java.

CGI are a language-independent mechanism of how HTTP requests are bound to server processes. It is (or was) used with many languages, especially Perl.


Ping & DNS - my free Android networking tools app
Amit Kumargupta
Ranch Hand

Joined: Apr 13, 2007
Posts: 54
servlets are excuted as threads and servlets are language independent.


CGI are excuted as process and CGI are language dependent.


Hi Ulf Dittmer

I think I am wrong but I read this line (servlets are language independent) in some article.



Can you clear me this point
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Originally posted by Amit Kumargupta:
Can you clear me this point


Could you write a servlet in FORTRAN? COBOL? As a shell script?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Amit Kumargupta
Ranch Hand

Joined: Apr 13, 2007
Posts: 54
Hi Bear Bibeault and Ulf Dittmer

Sorry for that. Yes I am wrong.
I apologize for wrong phrase.
sunny dhoni
Greenhorn

Joined: Jul 24, 2007
Posts: 9
Originally posted by Amit Kumargupta:
[QB]servlets are excuted as threads and servlets are language independent.
the same client may give a request but it can access the same instance so,it can initialize only once and it cannot create a multiple instance for single client.
so,if we avoid the multiple instance use servlets.


In case of servlets, there is no concept of request coming from single client as far as handling those requests is concerned. every new request (from same client, unless cookies are enabled or from diff client) is considered separate.
a new thread of execution is created for every request and has nothing to do with instances of the servlet. there is always a single instance of servlet irrespective of whether the request is coming from same client or a different client.


You have the right to remain silent. Anything you say will be misquoted, then used against you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

"sunny dh", please check your email for an important message from me.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: CGI and servlets
 
Similar Threads
CGI vs Servlets
existed code in perl and need to enhance in jsp
servlet -- cgi
whats the difference in CGI and servlets
CGI and Servlets