Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Signature of all the doXxx() methods

 
Dirk Lombard
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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?
 
Kalyana Sundaram
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Kiaama Liames
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic