Sunday, June 18, 2017

GenericServlet

To implement the Servlet interface, one needs to provide classes for all methods specified in the interface, even if the method is not used by the servlet.  To simplify coding, GenericServlet is an abstract class that implemented the Servlet inteface. GenericServlet supplies implementation for the method in the interface so that the real servlet class only needs to override those method it uses.

GenericServlet also saves the ServletConfig object passed by the servlet container to the init method in a persistent variable so the real servlet can access it later on.  GenericServlet adds another init method with no argument for the real servlet to override with its specific code.

GeneicServlet is implemented as abstract class as it expects the real servlet implementation override one of more methods before it is used.