This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HTTP Post

 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I got this question from j2eecertificate mock exam:

Which method would you override from the abstract class HTTPServlet to handle HTTP POST requests?
1. protected void doPost(HttpServletRequest req, HttpServletResponse resp)
2. public void doPost(HttpServletRequest req, HttpServletResponse resp)
3. protected void doPost(ServletRequest req, ServletResponse resp)
4. public void doPost(ServletRequest req, ServletResponse resp)
5. None of the above

I answered 2 but it says its 1.

Is this because j2eecertificate has lower servlet spec?
 
Deepika Pereira
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the Servlet API. All methods in the abstract class HttpServlet excepting "service" are protected void.

Hence the answer should be 1 according to me.
However in your Servlet class which is extending the HttpServlet you can declare it to be public as the visibility can be widened but not narrowed.

Hope this helps.
Cheers
 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deepika,

Thanks! That really helped!
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!