Sun Certified Web Component Developer/Section1
The Java Servlet Technology
editServlets works as CGIs, that means that they generate dynamic content to return to the user through the Web Container. The main advantage of a servlet, comparing to CGI applications is that the Web Container does all the hard work of processing the HTTP request and handling all the details of the protocol, giving to the programmer only object representation of requests and responses.
This advantage take from the application programmer the responsibility of redoing a work so many times done before. Of course, well built and known libraries could do that too, but there are many other advantages too. Following are a few of them.
- Built on Standards - JEE is built over standards. These standards are defined by JSRs. The java community process is very efficient in defining standards and new technology that world wide companies use in their enterprise softwares because these companies are behind the committees that define, process and vote the new standards. So the standards guarantee that, at least, the specifications were well grounded with design patterns used in day-to-day proven applications. That gives the programmers another advantage, because they don't have to rethink what others, generally very more experienced programmers, had already thought.
- One Instance - When handling a servlet, the web container maintains only one instance of it in memory, created at the first time it was requested, and removed when the server is stopped. CGI scripts do not do that, first because they aren't built over standards, so the server doesn't know how it works, secondly, it is just a program, and can be written in any language (including Java), it will be started and executed as a normal operational system process.
- Infrastructure - The Web Container offers much more than object representations of the request and response. It offer many other objects that can be very handy like session context, application context, filters, listeners and many more. These gives the servlet a whole context that inserts it in a real application instead of a one time only request/response with the client.