This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

pubic and protected service method  RSS feed

 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When ever a request comes to a servlet, the container directs it to public void service(ServletRequest req,ServletResponse res),which in turn calls protected void service(HttpServletRequest req,HttpServletResponse resp).

I understand that it is necessary to override the public service method(otherwise the class overriding HttpServlet will become abstract). Is it not possible that we directly call the protected service method,while simultaneously providing empty implementation for the public service method.
 
leon fan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want inherit from HttpServlet, you do not need to override the public "service" function as HttpServlet have implement it and will forward it to protected "service" function.

If you inherit your Servlet from GenericServlet, then you need override the "service" function, but no protected "service" function now.
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My question was regarding HttpServlet. Why there are two service methods.Will one servlet not serve the purpose.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!