Saturday, May 16, 2015

Servlet Container

Web server accept a request in form of URL and returns the resouce request.  The resouce could be static content which will not change no matter how many times it is request.  Examples of static content are image, icon, text etc.  When wen server received a request for dynamic content, it hands off to another component such as a servlet.

Servlet is basically a java class which can be specified as a resource in the URL.  Web server will interface to a servlet container which manages (initializes, dispatches, destroys) the life cycle of a servlet, according to the servlet specification.  The servlet container also supports JSP file that commonly used by servlet.

Most of the time, the servlet generates HTML codes as part of the response.  In fact, most of the response comprises mainly static HTML codes with a few dynamic content.  Generating the response page via program writing out HTML code in string form is tedious and the code is hard to maintain.  A JSP file is a template comprises mostly the static HTML codes with a few funciton calls to incorporate in the dynamic content.  The JSP file will be compiled by the serlvet container transparently into a servlet to run.

The servlet container has the following components:
(1) Connector allows client to connect to the container in various protocol such as HTTP.  Container interacts with a pool of threads which is assigned to each client connection.  Servlet is expected to be thread-safe and runs in a multithreading environment.

(2) The main container contains level and level of subcontainers - Servlet Engine, Virtual Hosts, Application Context and Servlet Wrappers, used to process requests

(3) Supporting functions such as  security, JSP compiler, JMX, clustering etc.

No comments: