There are two things a Web Server Application alone can't do:
1) Generate Dynamic Content (generating dynamic / on-the-fly web pages)
2) Perform Operations with form Data.
To perform these operations, the web server application uses helper applications.
These helper Applications perform the operations and sends information back to the web server application. (The web server application thinks that the page received is just another static page.)
The non-Java term for the helper application is CGI(Common Gateway Interface).
Most CGI programs were written using Perl and now I would like to bring out the advantages of Java over Perl.
* Java is Performance effective. With Perl, the server has to launch a heavy weight process for each and every request for that resource.
* Now we might get a thought that similarly in Java, each instance of the JVM would be a heavy weight process.
* In our case, Servlets stay loaded only once. Client requests for a servlet resource are handled as seperate Threads of the single running Servlet. We don't have the overhead of starting the JVM and loading the class.
* It can be pointed out that Web servers are able to keep a single Perl program running between clients, but, the point is not all web servers can do that. It's a special case which doesn't apply to all Perl CGI programs.
* Furthermore, Servlets can be a J2EE Client, whereas a Perl CGI Program cannot!
More to be discussed with respect to J2EE Clients.