• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
  • Himai Minh
  • Carey Brown
  • salvin francis

Implementing methods from HttpServlet

Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all. I got this question from www.jdiscuss.com. I am a bit confused.
Question No: 5 (Question ID: 796)


Consider the following code:
public class WWServlet extends HttpServlet
What methods do you need to implement so that it compiles without any errors?


Select 1 correct option.

A service()

B doService()

C doGet

D all doXXX methods

E No method as HttpServlet has dummy implementations.

Answer E
GenericServlet has an abstract service(ServletRequest, ServletResponse)
method. HttpServlet extends GenericServlet and provides a concrete
implementation of the service() method. It also provides the empty
implementation for the doXXX() methods.
But the API says:
Provides an abstract class to be subclassed to create an HTTP servlet
suitable for a Web site. A subclass of HttpServlet must override at
least one method, usually one of these:
doGet, if the servlet supports HTTP GET requests
doPost, for HTTP POST requests
doPut, for HTTP PUT requests
doDelete, for HTTP DELETE requests
init and destroy, to manage resources that are held for the life of the servlet
getServletInfo, which the servlet uses to provide information about itself

Is the answer E because the API is only saying you HAVE to override one
of these to provide functionality, not to allow compilation? I dunno. Can
anyone tell me?
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not to be a smart a** but did you try it and see what it does?
?One thing I learned in the programmers test is to make sure you take the questions literally and dont read anything into them. In this case it is asking about if it will compile or not. Try not to read anything else into the question.
By the way it will compile, but you'll get an error when you try to access it in a browser.
Hope that helps
Dave Thomas
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. Thanks. Thats all I needed to know.
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic