• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why generic servlet is an abstract class?

 
rahul S Sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to my knowledge, Generic Servlet class implements Servlet interface and it gives definition of all the methods present in Servlet interface except service() method. service() method is abstract in Generic Servlet class, that's why Generic Servlet is an abstract class.Please correct me if I am wrong or is there anything I can add in my explanation.
regards...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this is basic Java. If any method is abstract, then the class must be abstract.
 
rahul S Sharma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about HttpServlet class? This class doesn't have any abstract method, still is an abstract class.
 
Arun Giridharan
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you can make , even though the class doesn't have any abstract methods , for me the main reason i could say is doPost() or doGet() or other HTTP method than this , are just by-passing means it doesn't have any logical code in it . (This may be the main reason)
{Is it correct Bear Bibeault .}

 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpServlet is abstract because they don't want you instantiating it without subclassing it. Pretty much because there is no use at all. Java does a lot to protect developers from their own stupidity (checked exceptions, strong typing, ...), why shouldn't they do that here? :P
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GenericServlet IS-A Servlet . and this GenericServlet has some common functionality/method to the Servlet class. As of Now, there is a HttpServlet which is specific to the Http protocal extends GenericServlet and uses some servlet methods. in future, pretend there is a FTPServlet which may be extends GenericServlet.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The think about HttpServlet is that while it's completely useless without overriding one of the service methods (hence making it abstract), it would be a pain to have to implement all the service methods if all you wanted was something to respond to GET requests. So that's why those methods aren't abstract.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic