• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Implementing methods from HttpServlet

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)

Problem

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


Options

Select 1 correct option.

A service()

B doService()

C doGet

D all doXXX methods

E No method as HttpServlet has dummy implementations.


Answer E
Reason:
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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave
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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool. Thanks. Thats all I needed to know.
 
I am mighty! And this is a mighty small ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic