I was checking the Servlet API and I noticed that GenericServlet is an abstract class that implements the javax.servlet.Servet interface. I was wondering why the authors of GenericServlet class declared an abstract method "service(ServletRequest req, ServletResponse res)" if this method is already declared in the interface javax.servlet.Servlet. Any idea?
Generic Servlet is abstract class and implements both javax.servlet.Servlet and javax.servlet.ServletConfig interface. This class implements Servlet interface, it provides default implementation of all the methods available in Servlet and ServletConfig interface. service() method is still abstract in GenericServlet which means any servlet extending Generic Servlet has to provide implementation of service() method. Because this method is the main method where complete logic of your servlet goes and how can a generic servlet knows which logic to execute. If this method is not abstract then developers might leave this method unimplemented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With