File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes protected modifier of doGet(), doPost() etc. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "protected modifier of doGet(), doPost() etc." Watch "protected modifier of doGet(), doPost() etc." New topic
Author

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

Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

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.


"A problem well stated is a problem half solved.” - Charles F. Kettering
SCJP 6, OCPJWCD
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

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.


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: protected modifier of doGet(), doPost() etc.
 
Similar Threads
Signature of all the doXxx() methods
servlets
doGet and doPost
is there any getLastModified example?
Can we Have Write Service,doGet,doPost method implementation in a single servlet