Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what code will be there in init() of GenericServlet

 
vianyrajnish rajnish
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

1... what code will be there in init() and destroy() (overridden method from Servlet interface) of GenericServlet . ?

scenario::::

if override the destroy() of the GenericServlet in our own servlet class
like .... class Myservlet extends HttpServlet
{
.... here override destroy method
}

2. In this case, Is that destroy() of Myservlet class will be called by container?
3. is there any case like init(servletconfig) calling init() in GenericServlet ?... i mean destroy of Myservlet an call destroy of Genericservlet ..with super.destroy()?




Thanks,
VinayRajnish
 
Srinivasan thoyyeti
Ranch Hand
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vianyrajnish rajnish,

Job of Init(ServletConfig) in GenericSerlvet
--------------------------------------------
1. Generic Servlet stores ServletConfig supplied to init(ServletConfig) as instance variable becuase someof the methods like getServletContext() need ServletConfig to get the context out of it.

2. calls init() method.


What we need to do in MyServlet extends GenericServlet(recomended way):
----------------------------------------------------------------------
CASE 1 : As init(SerlvetConfig) is used to store ServletConfig object.
Do not over-ride that and over-ride init().

what happens:
Continer calls the init(SerlverConfig) and that method inturn calls the over-ridden method init() written by us.

CASE 2: You can over-ride and init(ServletConfig) without disturbing the intent of it.

but your over-ridden method must look like this:

[ May 06, 2008: Message edited by: Srinivasan thoyyeti ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic