aspose file tools*
The moose likes Servlets and the fly likes what code will be there in init() of GenericServlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "what code will be there in init() of GenericServlet " Watch "what code will be there in init() of GenericServlet " New topic
Author

what code will be there in init() of GenericServlet

vianyrajnish rajnish
Ranch Hand

Joined: Apr 22, 2007
Posts: 70
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

Joined: Feb 15, 2007
Posts: 557
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 ]

Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
 
Consider Paul's rocket mass heater.
 
subject: what code will be there in init() of GenericServlet