Servlets, Filters, and Listeners
All new Java web-tier technologies, such as JSP, JSF, and portlets, are defined on top of the API that started it all: the Servlet API. A servlet is a Java class that processes a request from a client and produces a response. Most implementations of the JSF specification use a servlet as the entry-point for the page requests, and some JSF-based applications may also include a few servlets and other classes defined by the servlet specification, such as listeners and filters.
The Servlet API is general enough to allow servlets to deal with any
request/response-based protocol, but it’s almost
exclusively used with HTTP. The API consists of two packages: the
javax.servlet package contains classes and
interfaces that are protocol-independent, while the
javax.servlet.http package provides HTTP-specific
extensions and utility classes.
For HTTP processing, one class and two interfaces make up the bulk of the API:
-
javax.servlet.http.HttpServlet This is the base class for most servlets. It contains empty default implementations of two methods that can be overridden by a subclass for initialization and release of internal resources used by a servlet:
init()anddestroy( ). Theinit()method is called once before the servlet is asked to process its first request, and thedestroy()method is called just before the servlet is taken out of service.The base class also provides default implementations of the request processing methods, one for each HTTP request type: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access