This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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

Win a copy of Building Microservices this week in the Design forum!
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

what code will be there in init() of GenericServlet

vianyrajnish rajnish
Ranch Hand

Joined: Apr 22, 2007
Posts: 70

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


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()?

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%)
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: what code will be there in init() of GenericServlet
It's not a secret anymore!