What should it do? HttpServlets are designed to respond to specific HTTP requests. I suppose the designers of this API could have added do-nothing methods to HttpServlet and not made it abstract, but I can't think of a good reason for doing this.
Originally posted by Amit Ghorpade: And what about the doGet() and doPost() methods?
If the class were concrete, what would the default implementation do?
They are not abstract methods (the programmer does not have to override either of them). Therefore there must actually be a default implementation.
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 did not meant to say that the doGet() and doPost() methods are abstract,I meant one needs a override to make his own implementation.
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.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
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.
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
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
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.
Since there would be no point in instanciating and running an instance of HttpServlet, it makes perfect sense for it to be abstract.
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.