Can anyboby tell me why we should use a servlet instead of cgi-bin for webThe short answer is that cgi-bin programs:
applications?or which one is better?
- Spawn a fresh process for each request. Servlets operate within a single, ongoing process. It's more efficient.
- cgi-bin programs are reloaded and re-parsed on each request. Servlets are loaded once. Also, if you have a JIT compiler, Servlets become native code after the first run!
- Servlets may be deployed with little or no changes on a wide variety of architectures. Develop a Servlet on Linux and deploy it on an AS/400 -- much better for large development teams.
- Servlets have better control over the HTTP protocol. Accessing things like cache-control headers and authentication information requires a lot of cheesy hacks for cgi-bin programs. In other words, Servlets leverage technology available to make web browsing faster and more efficient.
- Java programs are usually easy to understand by new programmers. Shell scripts and perl programs can look like gibberish to new developers, unless the original author takes care to format and document them precisely. Servlets are the safest architecture for projects which use consultants or have a long lifespan (5 years).
-- Charles
