• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need solution for Question

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

service()


doService()


doGet


all doXXX methods


No method as HttpServlet has dummy implementations.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question not clear
 
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For compilation, there is no need to implement any method.


public class WWServlet extends HttpServlet
{

}



it works fine
 
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah....you don't need to but you can implement the doXXX methods....the question has not been framed properly
[ December 03, 2006: Message edited by: Sayak Banerjee ]
 
author
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

The question is "OK" and the answer is the last one: no methods need to be implemented to make the WWServlet class compile.

However, I would argue that this is not a very good question, because it does not measure any reasonable skill or knowledge. A better question would be to ask "Given this servlet class, what would happen if you issued a GET request on this servlet?" Without looking it up, can anyone quess the answer?

-Bryan
[ December 03, 2006: Message edited by: Bryan Basham ]
 
Ranch Hand
Posts: 563
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bryan Basham:
Hi all,

The question is "OK" and the answer is the last one: no methods need to be implemented to make the WWServlet class compile.

However, I would argue that this is not a very good question, because it does not measure any reasonable skill or knowledge. A better question would be to ask "Given this servlet class, what would happen if you issued a GET request on this servlet?" Without looking it up, can anyone quess the answer?

-Bryan

[ December 03, 2006: Message edited by: Bryan Basham ]




I think the container will display an error page complaining that there is no doGet(...) method defined.
But I have another question, the specs say :
"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 "

I do not understand the "at least one method" part here.
Since a class that extends the class HttpServlet without implementing any method will compile.
Can you explain ?
 
Bryan Basham
author
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done, Celinio, that is correct. Specifically, the default implementations of the doXyz methods in HttpServlet returns the 501 code (functionality not implemented) in the response.

And to answer your question about the servlet spec. IMHO, this line in the spec should be rewritten like this: "To be useful, a subclass of HttpServlet must override at least one method..." Yes, it is true that an empty servlet class definition will compile and can be installed in a web container, but what use will it serve? None!

HTH,
Bryan
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic