• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet

 
Prashanth Bhanu
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Friends,
A basic question on servlet.We have GenericServlet class and is declared as a Abstract class,
We have one more class httpServlet is again an Abstract class which extends our Generic Servlet class.So it is learnt that what all classes extends httpServlet class, must implement atleast any one of the methods listed below.
doGet
doPost
doPut
doDelete
init
getServletInfo
My doubts are
1)Why GenericServlet is declaed as abstact as it has no single method as abstract?
2)How does the rule applied on httpServlet class as what all classes extends this class must
implement atleast one of the above methods?
thanks in advance for helping me to know the hidden strategy
prashanth
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)Why GenericServlet is declaed as abstact as it has no single method as abstract?
Becuase it's not meant to be used directly. The intent is for it to be extended.


2)How does the rule applied on httpServlet class as what all classes extends this class must
implement atleast one of the above methods?

You don't have to implement any of those methods. They're all implemented for you. You could certainly write and compile a servlet with none of those methods in it. It just wouldn't do anything.

You'll want to override one of those methods if you intend to have it do some work for you.

Think of the HttpServlet as a template with all the heavy lifting already done for you.

thanks in advance for helping me to know the hidden strategy

There's nothing hidden about it. It's all publicly documented in both the
API and in the Servlet Spec.
[ February 16, 2005: Message edited by: Ben Souther ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic