Tomcat Servlet Interaction
Tomcat Servlet Interaction
Although its flexible configuration and interoperability with supporting technologies have
enabled Apache Tomcat to act as a web application server in many circumstances,
Tomcat is primarily a Java servlet container.
Utilizing its implementation of the Java Servlet and JSP APIs, Tomcat is able to receive
requests from a client, dynamically compile a container-managed Java class to handle
the request as specified in the relevant application Context, and return the result to the
client. This method of generating dynamic content enables extremely fast, threaded,
platform independent processing of requests.
Furthermore, as the Java Servlet specification is designed for interoperability with all
other major Java web technologies, a servlet hosted on a Tomcat server is able to
leverage any resource that Tomcat makes available to it. Tomcat's nested hierarchical
XML configuration files allow for extremely fine-grained resource access control, while
maintaining loose coupling, ease of deployment, and logical, human-readable
architecture descriptions.
In this article, we'll take a look at how Apache Tomcat uses Servlets to quickly deliver a
wide range of dynamic content to a client.
The lifecycle of a typical servlet running on Tomcat might look something like this:
Combination of Components
Using servlets and the resources they access in conjunction with static HTML pages
and JSP pages, which contain a mixture of HTML and Java code, and can call servlet
methods using either native tag libraries or custom tags, Tomcat is able to present a
user with a dynamic, secure, persistent web application.
For example, a user might access a page where dynamic user interface objects are
handled client-side with AJAX, CSS, and HTML5 interacting with the DOM, while user
information is pulled from a database via a JSP tag that interacts with a servlet method.
This allows the presentation of a page to be completely separated from any business
logic, for improved security and design flexibility.