• 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

protected modifier of doGet(), doPost() etc.

 
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Feeling confused about the access modifier of the doGet(...), doPost(...) and other methods of HttpServlet class.

How come it is protected instead of public?

Please take a look at the following Servlet:


As per my understanding, "protected" modifier of doGet() means that a client has to be in the same package (or a child - through inheritance) to access doGet(). So how will the invoking JSP or the Container access it?

Hope my question makes sense.
 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nidhi!

That's quite interesting question and you made me to take some time with it :-)

I think that the container calls the Servlet.service(-) method (which is public). It then calls the HttpServlet.service(-) method which is protected and it then call doXxx(-) method.

So, the public access for Servlet.service(-) method is enough for the container to operate on servlet.
 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pedro Kowalski wrote:I think that the container calls the Servlet.service(-) method (which is public). It then calls the HttpServlet.service(-) method which is protected and it then call doXxx(-) method.

So, the public access for Servlet.service(-) method is enough for the container to operate on servlet.



Got it! Didn't think of the public service(...) method between the container & the doXXX(...) methods!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic