wood burning stoves 2.0*
The moose likes Servlets and the fly likes why CGI is used? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "why CGI is used?" Watch "why CGI is used?" New topic
Author

why CGI is used?

James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

I am learning about servlets and JSP... In that process i read(very little) how CGI(scripting) works . I read that for every request that a CGI receives it creates a new heavy weight thread but in servlets it not the case it only creates a light weight thread. I felt that creating a heavy weight threadfor every request by CGI can be considered as a very valid drawback. BUT still CGI programs are used extensively. So there must be some thing in CGI that is a real good advantage that is masking the above mentioned disadvantage.
What is THAT advantage ???
Are there any similar disadvantage in using servlets ???

SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

Well, I don't see CGI still being used extensively. But regardless, the barrier to entry is very low as no language like Java needs to be learned.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Bear Bibeault wrote:Well, I don't see CGI still being used extensively. But regardless, the barrier to entry is very low as no language like Java needs to be learned.

Oh...
i thought CGI is more used than servlets....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42365
    
  64
It's impossible to tell from the URL whether CGI is or isn't used. Even if the URL contains a string "cgi" or "cgi-bin" or some such, that may just be for historical purposes, while the actual CGI mechanism has long been replaced by a more modern approach.


Ping & DNS - my free Android networking tools app
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Ulf Dittmer wrote:It's impossible to tell from the URL whether CGI is or isn't used. Even if the URL contains a string "cgi" or "cgi-bin" or some such, that may just be for historical purposes, while the actual CGI mechanism has long been replaced by a more modern approach.

Oh... i never knew this... Actually i used to think if the url has something like "cgi" or "cgi-bin" then CGI is used.
With what did they replace it..

If they have replaced then why is that in the head first servlets book they still talk about that heavy weight issue???
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42365
    
  64
Actually i used to think if the url has something like "cgi" or "cgi-bin" then CGI is used. With what did they replace it..

CGI is mainly used for transferring handling of a web request to an external process (like a Perl interpreter). Modern servers (like GlassFish and Tomcat) handle all that internally, though, with no external processes to fire up. And even if more than one process is involved (like in an Apache httpd/Tomcat combination, or if using FastCGI), both processes are running already, which makes for much smaller overhead.

If they have replaced then why is that in the head first servlets book they still talk about that heavy weight issue?

It would help if you quoted the passage you're talking about.
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

HF servlets, pageno :28 wrote:Performance,for one thing.With Perl,the server has to launch a heavy weight process for each and every request for that resource

Actually, this is part of a conversion between CGI and servlets.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42365
    
  64
That statement in HFSJ isn't quite accurate. Mechanisms like FastCGI are available that do NOT launch a new child process for each request. That's also true when using mod_perl with Apache httpd.
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

Thanks Ulf Dittmer, i would go ahead and try to understand more about FastCGI.
And one more thing , i also want to know , which is used more CGI or servlets( percentage).
i know its a stupid question, it would really depend on the situation . But still you would have (i guess) noticed it.
Can you tell in terms of % ??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42365
    
  64
As I mentioned above, there's no way to tell from a URL if CGI is used, or if servlets are used, or if some other technology I used. So I'm not aware of any statistics about that.
James Tharakan
Ranch Hand

Joined: Aug 29, 2008
Posts: 580

ok..
Thanks buddy
 
 
subject: why CGI is used?