aspose file tools*
The moose likes Servlets and the fly likes Why the service methods in HttpServlet  abstract class are protected? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why the service methods in HttpServlet  abstract class are protected?" Watch "Why the service methods in HttpServlet  abstract class are protected?" New topic
Author

Why the service methods in HttpServlet abstract class are protected?

Suresh Khanna
Greenhorn

Joined: Jan 04, 2004
Posts: 16
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

Joined: Dec 23, 2003
Posts: 101
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why the service methods in HttpServlet abstract class are protected?
 
Similar Threads
how many methods are called???
about protected void doGet() ?
pubic and protected service method
service ( ) method overriding or overloading?
Default implementation of service method in HttpServletClass