Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Java Servlet vs CGI

Posted on 1999-07-21
5
Medium Priority
?
1,057 Views
Last Modified: 2013-11-24
Dear all,

Can anyone tell me why Java servlet is better than CGI?
0
Comment
Question by:benson031397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Accepted Solution

by:
masato earned 30 total points
ID: 1246745
CGI is using platform-specific APIs, but Servlet is using Java. Which means "Write Once, Run Any Server"
Servlet can handle multiple requests, and can synchronize requests.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1246746
usually CGI starts another process.
servlet uses just another Thread.
0
 
LVL 1

Expert Comment

by:Astroman
ID: 1246747
As stated, a new process is required for each CGI request. This means new stack frame, etc and therefore lots of resources. Servlets have only one copy running (usally. A servlet can be aliased to a diffenent name which will run independently), and all servlets share a single virtual machine.

CGI is usually written in interpreted languages(i.e. sh, or perl) which are slower than native apps. This can be avoided by writing in something like C, but then it is machine dependent. Servlets are machine independent and run nearly as fast as native code. Because the process is only started once the startup overhead can be disregarded. Not so with CGI.

CGI is also less secure than servlets. Servlets run in a secure sandbox, so shouldn't be able to do any damage outside of the domain of the servlets. The worse thing that can happen is that you can bring all the servlets down. With perl CGI (for example) it's possible to trick badly written scripts into executing arbitrary chunks of code. Very dodgy.

Are they good enough reasons to use servlets over CGI?

Leon
0
 
LVL 2

Expert Comment

by:aziz061097
ID: 1246748
Another reason I can think of is database connection , a CGI program has to make a connection to the database for every request (if it requires database results) whereas a servlet can maintain the connection for various requests . Database connection time is a very costly (time consuming) operation .
0
 
LVL 1

Expert Comment

by:Astroman
ID: 1246749
Come on benson, I think we've all given you some good answers, how about dishing out some points!
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question