Java Tutorial - Java Script : Web Servers versus Servlet Containers

Java Tutorial - Java Script :

Web Servers versus Servlet Containers


In Figure 5.1, we show the Web server as a front end for the servlet container. This seems to be the most common configuration for production-based deployment, but note that this configuration is optional for many servlet containers. Most servlet containers have the ability to handle HTTP directly instead of relying on the Web server to do so. Remember: the Web server returns a file or executes a program based on the request. Because the servlet
container also understands HTTP, it’s fairly simple to create servlets to look up files and return them or execute programs returning the standard output. These functions are now typically built in and provided with most currently
available servlet containers. So the question is: Why continue to use a Web server with a servlet container?
The answer is that you often don’t need to use the Web server. For most development uses, there is no need for a separate Web server at all. The servlet containers we will look at handle static content just as well as servletgenerated content. But for production purposes, having a Web server, such as Apache, deal with static content can be beneficial. For example, the Web server is often optimized for serving static files and can do this faster than the servlet container. There are also techniques that can be used with Apache for supporting load balancing and other features that may help a site to be more scalable. These come at a cost of complexity, but that is the trade-off