• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Signature of all the doXxx() methods

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Servlet specification p.231 says that the method signature is
protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException. Yet in the HFSJbook all the examples show public void doGet..... So is it public or protected?

What is the correct signature? What will be excepted as right in the exam?
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We create our own servlet by extending the HttpServlet and overriding the doGet() or doPost(). When it comes to overriding a method defined in the parent class, the subclass can either have the same method signature defined in the parent class or the access specifer can be in widening manner. i.e., default => protected => public.
Hope this helps. Refer Overriding for further details
 
Dirk Lombard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for pointing out the Overriding rule.
So if you have a question like this in the exam:
Which of the following is the correct full signature of a method of HttpServlet that is called for an HTTP GET request?
Must it then be protected?
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HttpServlet abstarct class has protected void doGet(HttpServletRequest req,HttpServletResponse resp) which will be called for an HTTP GET request .

In case you extend this class then the modifier of doGet can be both public and protected since the questions asks about the signature in HttpServlet then it should be protected
 
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic