aspose file tools*
The moose likes Servlets and the fly likes Why generic servlet is an abstract class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why generic servlet is an abstract class?" Watch "Why generic servlet is an abstract class?" New topic
Author

Why generic servlet is an abstract class?

rahul S Sharma
Greenhorn

Joined: Jun 08, 2011
Posts: 21
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

Joined: Jan 10, 2002
Posts: 60997
    
  65

Yes, this is basic Java. If any method is abstract, then the class must be abstract.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
rahul S Sharma
Greenhorn

Joined: Jun 08, 2011
Posts: 21
What about HttpServlet class? This class doesn't have any abstract method, still is an abstract class.
Arun Giridharan
Ranch Hand

Joined: Sep 30, 2010
Posts: 290

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

Joined: Aug 06, 2010
Posts: 542
    
    4

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


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Apr 06, 2010
Posts: 4363
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why generic servlet is an abstract class?