Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why GenericServlet declares service method? [closed]

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?

like image 976
Bravo Avatar asked Nov 10 '22 10:11

Bravo


1 Answers

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.

like image 129
Zia Avatar answered Dec 04 '22 10:12

Zia