File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Implementing methods from HttpServlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Implementing methods from HttpServlet" Watch "Implementing methods from HttpServlet" New topic

Implementing methods from HttpServlet

Dave Thomas
Ranch Hand

Joined: Nov 05, 2001
Posts: 30
Hi all. I got this question from 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?
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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

Joined: Nov 05, 2001
Posts: 30
Cool. Thanks. Thats all I needed to know.
I agree. Here's the link:
subject: Implementing methods from HttpServlet
It's not a secret anymore!