Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract HttpServlet??

 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,
I am wonderring what makes the class javax.servlet.HttpServlet abstract? It seems like the public service method is implemented as it dispatch to the protected service method. And it seems like the protected method is also implemented as it dispatch to a doXxx method. It seems also that all the doXxx method have at least an empty body as overriding only one of them is enough. So what makes that class abstract?
Is there any reason for calling that class abstract?
Thx for your help!
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody to help me?
 
Zheng Huang
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not use it as is. You have to sub-class it and override one of the following:
doGet, if the servlet supports HTTP GET requests
doPost, for HTTP POST requests
doPut, for HTTP PUT requests
doDelete, for HTTP DELETE requests
init and destroy, to manage resources that are held for the life of the servlet
getServletInfo, which the servlet uses to provide information about itself
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Zheng for your answer. Anybody else has an explanation (which is not pasted from the API, I also have it )
 
Paulo Salgado
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like they want to guide you to use the public and protected service methods the way they are (deciding which method to call based on the HTTP method) but giving you the freedom to implement the doXxx() ones to fulfill the requests. At the same time they don't want you to use an HttpServlet object since it won't do a thing with the request. In other words, they want HttpServlet to serve as a template for you own HTTP servlets, not as a real servlet handling requests.
This is just an opinion of course.
 
yi zhu
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess the default implementation code of Httpservlet is useless, so they make it abstract to invite you to provide more meaningful code.
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, that's what I thought, but I wondered if there wasn't another reason for it. Anyway thank you all for your help
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpServlet has dummy implementations of all methods declared in it.You dont have to override any method but if you extend GenericServlet then service() has to be overridden.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic