• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need solution for Question

 
ramya ray
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • 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.
 
Bachi Taurean
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question not clear
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For compilation, there is no need to implement any method.


public class WWServlet extends HttpServlet
{

}


it works fine
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bryan Basham
author
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • 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 ]
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic