File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes disadvantages of servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "disadvantages of servlets" Watch "disadvantages of servlets" New topic

disadvantages of servlets

Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
I was mentioned a lot of advantages of servlets (to CGI), such as efficient, convienent, powerful--). What are disadvantages, besides the tedious HTML code inside println ()?
Tony Alicea

Joined: Jan 30, 2000
Posts: 3226
In principle Servlets are always better than CGIs. But since CGIs have been around for such a long time, there's more of them in the public domain.
And any Web Application that has many Servlets with a lot of HTML in println statements may need to be redesigned. Use JSPs for presentation (View) instead, and Servlets for the Controller (MVC pattern).
My $0.02

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
The need to generate HTML code (in println or otherwise) is also present in CGI. From that point of view they are the same.
The drawbacks of servlets are few, but they include:
1. You need a special "servlet container" to run servlets, and most web servers (and thus most public hosting companies) don't include this.
2. You need a Java Runtime Environment on the server to run servlets. CGI is a completely language independent protocol, so you can write CGIs in whatever languages you have available (including Java if you want to).
3. Sometimes there are no Java interfaces to particular resources or devices. In this case writing a CGI in a language which does have native support for access to these resources or devices can be a lot simpler than setting up JNI to call through another language. And it might not even be possible through JNI.
4. Although each CGI requst usually requires a process start (which can make them a lot slower than servlets for short tasks) a CGI can be written in a fully compiled language and use fully compiled and optimized low-level system calls, so complex, long, or machine-dependent processing can be faster and simpler using CGIs
5. You can easily test a CGI on the command-line of the server: just set a few environment variables and run it to see the output. This is not easy with servlets.

Don't be discouraged, though. The list of advantages for servlets is much longer ...

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Simon Xu
Ranch Hand

Joined: Aug 16, 2000
Posts: 235
Thanks, Tony & Frank,
The questions were asked during an interview.
I agree. Here's the link:
subject: disadvantages of servlets
jQuery in Action, 3rd edition