jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes Why HHTP servlet is defined as abstract? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why HHTP servlet is defined as abstract?" Watch "Why HHTP servlet is defined as abstract?" New topic
Author

Why HHTP servlet is defined as abstract?

ravi lingala
Greenhorn

Joined: Nov 27, 2009
Posts: 10
Hi All,

Please clarify this.

1.Why HHTP servlet is defined as abstract servlet ?Even though it doesnt have any abstract methods.All the methods in it are all protected only.
2.If we dont override any do() method, then why our own servlet will become abstract?
avi sinha
Ranch Hand

Joined: Mar 15, 2009
Posts: 452

ravi lingala wrote:Hi All,
2.If we dont override any do() method, then why our own servlet will become abstract?


what does this mean ???

HttpServlet provides dummy implementation for all doXxx methods . there is no need to override them for compilation.
well we should override one of them to provide functionalities otherwise an error message will be generated by the container if the method is requested(not exception).
avi sinha


SCJP 5.0 SCWCD 5.0
ravi lingala
Greenhorn

Joined: Nov 27, 2009
Posts: 10
Thanks avi Sinha for giving clarification.
As per your clarification, if I don't override any doxx() methods in my servlet then my servlet will not become abstract.
we overrdie doXXmethods() only to provide functionality.
But I still did not understand why HTTP servlet is defined as abstract(if there are no abstract methods).
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41898
    
  63
if I don't override any doxx() methods in my servlet then my servlet will not become abstract.

No, it's the other way around - if you override one of the methods, then the class is no longer abstract.

But I still did not understand why HTTP servlet is defined as abstract(if there are no abstract methods).

To indicate that one of the methods must be overridden to obtain a meaningful servlet. If none of the doXYZ methods are overridden, then a 405 is returned for most HTTP methods - not useful at all.


Ping & DNS - my free Android networking tools app
ravi lingala
Greenhorn

Joined: Nov 27, 2009
Posts: 10
Thanks Ulf Dittmer
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why HHTP servlet is defined as abstract?