• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic