why HttpServlet is abstract?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Even though there are no abstract methods in it Why HttpServlet is abstract?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If the class were concrete, what would the default implementation do?
SCJP, SCWCD.
|Asking Good Questions|
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
They are not abstract methods (the programmer does not have to override either of them). Therefore there must actually be a default implementation.Originally posted by Amit Ghorpade:
And what about the doGet() and doPost() methods?
If the class were concrete, what would the default implementation do?
And in my observation, what the default implementation does is, for example: the doGet() method returns an HTML return code saying that the URL does not support the GET method.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
And in my observation, what the default implementation does is, for example: the doGet() method returns an HTML return code saying that the URL does not support the GET method.
I think that the GET method not supported error is returned by the container.
SCJP, SCWCD.
|Asking Good Questions|
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I think that the GET method not supported error is returned by the container.
We could discuss whether any result code is returned by the servlet or the container, but in this case the error code is returned by the methods in the HttpServlet class, as Paul said.
The javadocs of earlier version of the HttpServlet class used to state explicitly that the default implementation returns an error code about the method not being supported, but someone chose to remove that rather useful comment.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-

SCJP, SCWCD.
|Asking Good Questions|
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Paul Sturrock:
I suppose the designers of this API could have added do-nothing methods to HttpServlet and not made it abstract,
Not sure what that meant. Would you please elaborate?
I think the question probably came from the fact that there are no abstract methods in the HttpServlet class. So we could do without the abstract modifier. Couldn't we?
Shikhar
He who asks a question is a fool for five minutes; he who does not ask a question remains a fool forever - Chinese proverb
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
So we could do without the abstract modifier. Couldn't we?
It keeps new programmers from wasting time with questions like this one by giving immediate feedback from the compiler.
Bill
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Also, since a subclass of HttpServlet can be useful with zero, one, or up to all of the doXxx methods implemented, it makes no sense to force developers to implement any of these methods by declaring them abstract.
| When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |











