In Java, Servlet container (also known as aWeb container) generates dynamic web pages. So servlet container is the essential part of the web server that interacts with the java servlets. Servlet Container communicates between client Browsers and the servlets.
Servlet Container managing the life cycle of servlet. Servlet container loading the servlets into memory, initializing and invoking servlet methods and to destroy them. There are a lot of Servlet Containers like Jboss, Apache Tomcat, WebLogic etc.
How does this Servlet Container work?
• A client browser accesses a Web server or HTTP server for a page.
• The Web server redirects the request to the servlet container (Servlets are HTTP listeners that run inside the servlet container).
• The servlet container redirects the request to the appropriate servlet.
• The servlet is dynamically retrieved and loaded into the address space of the container, if it is not in the container.
• The servlet container invokes servlet init () method once when the servlet is loaded first time for initialization.
• The servlet container invokes the service () methods of the servlet to process the HTTP request, i.e., read data in the request and formulate a response. The servlet remains in the container’s address space and can process other HTTP requests.
• Web servlet generates data (HTML page, picture …) return the dynamically generated results to the correct location.