This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
In some mock exams, i saw that in the servlet which extends HttpServlet there would be no doGet method but the user invokes get methods either by clicking a link or typing the url in the browser address line. Now the answers would be 1. Throws error since no doGet method defined. 2. Invokes the default doGet method from HttpServlet.
I feel the second answer is right but the answer is other way. Is that right?
Hi Sunitha, In your servlet, you have to either override doGet or doPost.(99.9% of the time!). If you don't override doGet and say, you just click a link, the container will throw an error since you don't have the doGet method defined. Hope this helps.
Joined: Sep 18, 2003
Ritu, Thanks for the reply. I would implement doPost but not doGet, but doesn't the doGet method of HttpServlet will be executed since i haven't overridden the method from HttpServlet i would assume the default implementation of HttpServlet will be executed. I haven't seen in the API, that the doGet from HttpServlet is abstract method.
I think both the answers should be correct. If I does not implement the doGet(), the same from the parent will be invoked ( Java Rule). But the default implementation of doGet() method is container dependent and usually throw Server Error ( I Remember 500).
Even I had the similar kind of doubt. Did u get the precise answer for it? Other replies are much more confusing to me by sayin' both are correct. Is this what u r telling , dudes? Default doGet() in HttpServlet is called which throws errors if I dont override doGet()!!!
Oh my gosh!!! One reply says, it is vendor dependent!!! I am under the impression that HttpServlet is a concrete class. How can vendor touch that by any means in this world?
Joined: Dec 04, 2004
The HttpServlet is abstract class according to the specification provided by Sun. Also the implementation of the J2EE framework is provided by the Vendor and not by the sun.
I am using Tomcat 5. It is giving me following error message.
HTTP Status 405 - HTTP method GET is not supported by this URL