Forums Register Login

HttpServlet provides empty implementation for all do***()?

+Pie Number of slices to send: Send
Hi all,
Say, your Servlet only has doPost(), but a Get is sent to it, what will happen? Empty output, or Exception with status 405?
From Jwebplus, it says HttpServlet provides emptry implementation for all do***() methods, so there will be no Exceptions. But from the Mockexam on the ranch, it says Exception will be thrown. I tried it on tomcat, status 405 is returned.
What do you think?
Kyle
+Pie Number of slices to send: Send
Whenever we call a doXXX method of a servlet the container calls service method of HttpServlet which inturn calls the relevant doXXX method.
Since you have not overridden the doGet in your servlet class the default doGet method of HttpServlet is called (which does nothing).
Hence there is no question of throwing an exception.
+Pie Number of slices to send: Send
Thanks, Rajesh.
But the problem is, I tried it in Tomcat4, and I got a Exception with status code 405 (Http Method not allowed). And what's more, in the mock exam, there is one question with the correct answer saying an Exception should be thrown.
That's what makes me confused.

Kyle
+Pie Number of slices to send: Send
Hi Kyle,
What you are getting is not actually an exception. The default implemention of the doXXX methods call response.sendError() method to send an error message to the browser. This is not an exception.
The following source code for the doGet() method of HttpServlet will help you understand this better:
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 670 times.
Similar Threads
Why HHTP servlet is defined as abstract?
HTTP method GET is not supported by this URL
question about doGet not present..
Implementing methods from HttpServlet
Confusion in Mock exam qn
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 08:37:44.