• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q 10 page 60 Authore Charles lyons

 
vipin jain
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which abstract class or interface must be extended or implemented to provide an HttpServlet?

A) javax.servlet.Servlet(interface)
B) javax.servlet.GenericServlet(interface)
C) javax.servlet.GenericServlet(abstract class)
D) javax.servlet.Http.HttpServlet(abstract class)
F) javax.servlet.GenericHttpServlet(abstract class)

Can any one explain me what is mean of this question and what is answer?
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think question is asking (which appeared to be asking to me) what should we do if we are about to use HttpServlet? Then answer would be D but there's no Http package only http (don't know that is typo or..)?
 
vipin jain
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks vijith

the correct question is
Which abstract class or interface must be extended or implemented to provide an Http servlet?

And D) option is javax.servlet.http.HttpServlet
The book showing answere A....
so i am little bit confuse
i think you are right Question means how can we use HttpServlet and correct answere is D.......

Can any one cleare this thing is it book answere print mistake or we are going in wrong way......?
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since question is asking about, to provide a HttpServlet ( if we assumes that it means, we are to create a HttpServlet class of our own) then we can have that answer right? If that's the case question is not stating that clearly isn't it? Any ideas?
[ December 05, 2008: Message edited by: Vijitha Kumara ]
 
vipin jain
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
--------------------------------------------
if we assumes that it means, we are to create a HttpServlet class of our own
----------------------------------------
means if we are creating our own HttpServlet( not use HttpServlet which one is already available)
in this situation whe have to implement javax.servlet.Servlet since we have to overriddie there methods
Then there answere A is correct......
What do you think.?
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case I think either choice A (implement the Servlet) or C (extends the GenericServlet class which implements the Servlet interface of course) is possible.
[ December 05, 2008: Message edited by: Vijitha Kumara ]
 
vipin jain
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but As per over question
GenericServlet only overridde init () method
but in servlet there is all method including init(....)
so A is more better Compaire to C......
What do you think?
 
vipin jain
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry Vijitha.....

i think you are right

Thank's for help...
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, if you read the explanation on p.63 I think it pretty much answers your question:
Correct answer: A.
Only Servlet must ever be implemented---the others are just convenience classes. The appropriate (but optional) classes to use are C if you want a protocol-independent servlet, or D for an HTTP-specific servlet
In practise, very few containers provide support for any protocols other than HTTP, so usually you'll extend option D.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GenericServlet only overridde init () method
but in servlet there is all method including init(....)
so A is more better Compaire to C......
I'm a bit confused. But I don't think what you're saying is the right reason. It seems to me that you're saying you can't override init() if you extend GenericServlet---but you can since it isn't marked final. You can implement all the same methods in GenericServlet as in Servlet.

The key point this question tests is that you understand that you only ever have to implement the javax.servlet.Servlet interface to create a servlet. All the other classes which, directly or indirectly, implement Servlet are for our convenience, as programmers, only. The Web container only knows about the Servlet interface and will only invoke the methods found in it. HttpServlet, for example, is a convenience class which adds the doGet(), doPost() etc. methods to make our lives, as programmers, easier when working with the HTTP protocol. In fact what happens is:
  • The container calls the service(ServletRequest,ServletResponse) method
  • HttpServlet implements this method to call the protected service(HttpServletRequest,HttpServletResponse) method, casting the arguments to their HTTP variants
  • This method then invokes the appropriate doXxx() method depending on what HTTP method was used in the request (determined using HttpServletRequest.getMethod())
  • The diagram on p.53 also shows this process.

    Does that clarify it?
    [ December 05, 2008: Message edited by: Charles Lyons ]
     
    vipin jain
    Ranch Hand
    Posts: 122
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hello,

    Thank you so much .......
    Now i have cleared all things ......
    Again Thanks a lot...
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic