O'Reilly logo

Java Enterprise in a Nutshell, Second Edition by David Flanagan, Jim Farley, William Crawford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Web Applications

Now that we’ve seen a basic servlet, we can step back for a moment and talk about how servlets are integrated into the servlet container. Version 2.2 of the Servlet API popularized the concept of a web application installed within a web server. A web application consists of a set of resources, including servlets, static content, JSP files, and class libraries, installed within a particular path on a web server. This path is called the servlet context, and all servlets installed within the context are given an isolated, protected environment to operate in, without interference from (or the ability to interfere with) other software running on the server.

A servlet context directory tree contains several different types of resources. These include class files and JAR files (which aren’t exposed to clients connecting via web browsers), JSP files (which are processed by the JSP servlet before being fed back to the client), and static files, such as HTML documents and JPEG images, which are served directly to the browser by the web server.

Finally, there is a virtual component to the context. For each context, the servlet container will instantiate separate copies of servlets (even if those servlets are shared) and will create a private address space that can be accessed via the ServletContext class. Servlets can use this class to communicate with other servlets running in the same context. We’ll discuss this more later.

The simplest servlet installations will just ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required