Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why the service methods in HttpServlet abstract class are protected?

 
Suresh Khanna
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the service methods in HttpServlet abstract class are protected? While all the other methods in all classes and interfaces are public. Can anybody explain indetail.
protected void doGet(HttpServletRequest req, HttpServletRespone res)
protected void doPost(HttpServletRequest req, HttpServletRespone res)
protected void doTrace(HttpServletRequest req, HttpServletRespone )
protected void doOptions(HttpServletRequest req, HttpServletRespone res)
protected void doPut(HttpServletRequest req, HttpServletRespone res)
protected void service(HttpServletRequest req, HttpServletRespone res)
public void service(Servletrequest req, ServletResponse res)
Thanks in advance
Suresh K
 
Ken Robinson
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because those methods should NEVER be called directly by anything other than the service method. The web container will call the public serivce which will then decide what to do with the request. Making the service methods protected enforces this.
If you want logic in doGet/doPost that is available outside of a container generated call, move it into an other object instead of a servlet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic