Web Applications
A web application is software that is delivered by a server and rendered
by a browser. Java provides support for web applications through the
Servlet API.
The Servlet API
The Servlet API provides the specification for a servlet container. A servlet
container handles an HTTP request by delegating the request to a web
application, which in turn delegates the request to a Servlet.
A web application is packed into a web archive called a WAR file.
A WAR file
contains classes, libraries, and a deployment descriptor called
web.xml.
A deployment descriptor is a configuration file that
describes how an application
should be deployed. For example, the
web.xml file tells the servlet container
which URL patterns map to Servlets.
Servlets
Servlets
are singleton objects that are managed by a servlet container.
The container invokes the init() method when the servlet is initially loaded.
Incoming requests are delegated to the service() method concurrently.
Finally, the container invokes the destroy()
method when the application
is shutting down.
HttpServlet
is a Servlet implementation that contains methods
corresponding to HTTP requests, such as doGet(), doPost(), doPut(),
and doDelete(). HttpServlet provides
access to request parameters
as well as a session object that can store state across requests. Sessions are
correlated by an identifier that is stored in a cookie by the browser.