Step2 : Servlet API

1- javax.servlet – This package is used for protocol-less requests.

It contains 14 interfaces and 11 classes. (You don’t need to learn them all though)

2- javax.servlet.http- This package is used for http protocol requests.

It contains 8 interfaces and 7 classes. (again, you don’t need to learn them all)

Note– (i) javax.servlet package has subpackages, javax.servlet.http is one of them.

tabular comparison of some of the main classes and interfaces in javax.servlet and javax.servlet.http:

javax.servletjavax.servlet.http
ServletHttpServlet
ServletRequestHttpServletRequest
ServletResponseHttpServletResponse
ServletConfigHttpServletConfig
ServletContextHttpServletContext

As you can see from the table, the main differences between the two packages are that the classes and interfaces in javax.servlet.http are specialized for handling HTTP requests and responses, while those in javax.servlet are more general purpose.

1- Here is a list of some of the main interfaces in the javax.servlet package:

  1. Servlet: The main interface that all servlets must implement. This interface defines the methods that are called by the servlet container to initialize, service, and destroy a servlet.
  2. ServletConfig: An interface that provides initialization information for a servlet. A servlet can access this information using the methods of this interface.
  3. ServletContext: An interface that provides access to the information about the servlet’s environment. A servlet can access this information using the methods of this interface.
  4. ServletRequest: An interface that provides information about a client’s request to the servlet. A servlet can access this information using the methods of this interface.
  5. ServletResponse: An interface that provides information that a servlet uses to create a response to a client’s request. A servlet can access this information using the methods of this interface.
  6. Filter: An interface that defines methods that are called by the servlet container to filter requests and responses.
  7. FilterChain : An interface used to invoke the next filter in a chain of filters.
  8. ServletRequestWrapper and ServletResponseWrapper: These interfaces are used to wrap an existing request or response object, so that additional functionality can be added to it.
  9. SingleThreadModel : A marker interface which, when implemented by a Servlet class ensures that only one request at a time is processed.
  10. ServletInputStream and ServletOutputStream: used for reading and writing respectively in a Servlet.

This list is not exhaustive, but it should give you an idea of some of the main interfaces that are provided by the javax.servlet package.

2- Here is a list of some of the main classes in the javax.servlet package:

  1. GenericServlet: A convenience class that implements the Servlet interface, and is designed to be subclassed by developers. This class takes care of some of the low-level details of servlet management, so that you can focus on the business logic of your servlet.
  2. ServletException: A general exception that a servlet can throw when it encounters a problem.
  3. UnavailableException : Thrown when a servlet is temporarily or permanently unavailable.
  4. ServletInputStream and ServletOutputStream : These classes provides a means for reading and writing binary data to a client and a Servlet respectively.
  5. RequestDispatcher: This class allows a servlet to forward a request to another resource (servlet, JSP file, or HTML file) on the server, or to include the output of another resource in the response.
  6. ServletRequestAttributeEvent and ServletRequestListener : these classes and interfaces are used for listening to attribute events on ServletRequest.

This list is not exhaustive, but it should give you an idea of some of the main classes that are provided by the javax.servlet package. It’s worth noting that the majority of the class in this package are Event Listeners, Filters and Wrappers, which are helper classes used to interact with servlet container.