In this chapter, we will discuss how to develop and deploy Java servlets. Some of the
topics covered are:-
An explanation of what servlets are
-
Developing, configuring, packaging and deploying our first servlet
-
HTML form processing
-
Forwarding HTTP requests
-
Redirecting HTTP responses
Persisting data across HTTP requests
What is a Servlet? A servlet is a Java class that is used to extend the capabilities
of servers that host applications. Servlets can respond to requests and generate
responses. The base class for all servlets is javax.servlet.GenericServlet, this
class defines a generic, protocol-independent servlet.
By far, the most common type of servlet is an HTTP servlet; this type of servlet is
used in handling HTTP requests and generating HTTP responses. An HTTP servlet
is a class that extends the javax.servlet.http.HttpServlet class, which is a
subclass of javax.servlet.GenericServlet.
A servlet must implement one or more methods to respond to specific HTTP
requests. These methods are overridden from the parent HttpServlet class. As can
be seen in the following table, these methods are named so that knowing which one
to use is intuitive.