Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what code will be there in init() of GenericServlet

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Our first order of business must be this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic