Why Do I Need Servlets?

   

Java™ 2 Primer Plus
By Steven Haines, Steve Potts

Table of Contents
Chapter 21.  Servlets


Servlets are here to make your life easier. If the only option available was to write HTTP applications from scratch every time new functionality was needed, not much development would take place on the Web. Not many organizations could afford to write HTTP programs from scratch. The existence of the servlet container avoids the cost of having to include the entire HTTP header processing code in every program. Servlets extend classes that take care of all that work behind the scenes.

Another advantage of servlets is that they scale nicely. The servlet container is responsible for instantiating your servlet whenever it is needed. If it is needed a lot, the servlet container has the option of creating as many threads or instances of your servlet as its load-balancing algorithms indicates it needs.

Servlets make good use of machine resources. They run in threads that are created by the servlet container. Each individual HTTP application program runs in its own process.

Processes are far more expensive to create than threads, so the servlet approach is more efficient. Servlet containers can also pool connections so that the threads already created are reused instead of discarded. The ancestor of the servlet, the CGI program, lacked these features and has faded in popularity as a result.


       
    Top
     



    Java 2 Primer Plus
    Java 2 Primer Plus
    ISBN: 0672324156
    EAN: 2147483647
    Year: 2001
    Pages: 332

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net