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

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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic