Question:
What are the advantages of java servlet over CGI ?
dguna12
2009-07-31 13:40:02 UTC
related to the web application development..
Four answers:
Yamini
2009-08-01 00:52:26 UTC
1. Efficient

With traditional CGI, a new process is started for each HTTP request. If the CGI program itself is relatively short, the overhead of starting the process can dominate the execution time. With servlets, the Java virtual machine stays running and handles each request with a lightweight Java thread, not a heavyweight operating system process.



2. Convenient

Servlets have an extensive infrastructure for automatically parsing and decoding HTML form data, reading and setting HTTP headers, handling cookies, tracking sessions, and many other such high-level utilities. In CGI, you have to do much of this yourself.Besides, if you already know the Java programming language, why learn Perl too?



3. Powerful

Servlets support several capabilities that are difficult or impossible to accomplish with regular CGI. Servlets can talk directly to the Web server, whereas regular CGI programs cannot, at least not without using a server-specific API.



4. Portable

Servlets are written in the Java programming language and follow a standard API and thus are portable themselves.



5. Inexpensive

A number of free or very inexpensive Web servers are good for development use or deployment of low- or medium-volume Web sites.This is in contrast to many of the other CGI alternatives,

which require a significant initial investment for the purchase of a proprietary package.



6. Secure

One of the main sources of vulnerabilities in traditional CGI stems from the fact that the programs are often executed by general-purpose operating system shells. So, the CGI programmer must be careful to filter out characters such as backquotes and semicolons that are treated specially by the shell. Implementing this precaution is

harder than one might think, and weaknesses stemming from this problem are constantly being uncovered in widely used CGI libraries.

A second source of problems is the fact that some CGI programs are processed by languages that do not automatically check array or string bounds. Servlets suffer from neither of these problems. Even if a servlet executes a system call (e.g., with Runtime.exec or JNI) to invoke a program on the local operating system, it does not use a shell to do so. And, of course, array bounds checking and other memory protection features are a central part of the Java programming

language.



Hope ths helps you
2016-03-18 13:52:57 UTC
The biggest difference between CGI and servlets is performance. There is a single Java Virtual Machine running on the server, and the servlet is loaded once when it is called. It is not loaded again until the servlet changes, and a modified servlet can be reloaded without restarting the server or application. By using servlets, the developer doesn't have to worry about the inner-workings of the server. Form data, server headers, cookies, etc., are all handled for you by the servlet's underlying classes. Additionally, because servlets are written in Java, you can move them from one system to another for deployment and not worry about the OS or the type of server. This advances Java's whole notion of "write once, run anywhere."
HAL9000
2009-07-31 13:57:42 UTC
Personally, they both suck. Java servlets usually require more server resources to operate and bog down your server performance. CGI is also slow but not as slow as Java servlets. Using a text based flat database file with either just makes it even worse.



Java allows you to create applications which work as if it were a standard system application as oppose to CGI which is a scripting language mostly used for web site development and data file management. Java is mostly object oriented programming.



PHP / Zend Optimizer with MySQL databases is the way to go. It's the better option as far as data form processing goes. Java servlet may allow you to create and or run applications like chat rooms or digital clocks. However, there are a million chat rooms you can run with just CGI, PHP and MySQL as well as countless amounts of scripts.
?
2016-12-15 15:52:29 UTC
Advantages Of Servlets


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...