• 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

call super.init(config)...

 
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
I have two questions:
1.Normaly when we call super.init(config)?
2.Does ServletContext in servlet work directly with <context-param> tag in web.xml?
Thanks,
ELahe
 
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Originally, the reason that this method existed was to allow the servlet access to the ServletConfig object.However, this method is somewhat inconvenient to use because once the ServletConfig object is received, it must then be passed to the servlet's parent class. This is due to the fact that the GenericServlet object's init(ServletConfig) method stores the ServletConfig object and makes it accessible via the getServletConfig() method. Therefore, if the ServletConfig object is not passed to the GenericServlet parent class, it will not be accessible to the service() or destroy() methods and getServletConfig will always return null(unless the developer stores the ServletConfig and implements the getServletConfig() method himself) So you should pass this object to the parent.But API2.1 added init() which makes the job easier.
Server always calls the init(ServletConfig) regardless of which init method is over written by the developer.If you over write the init() then you inherit the init(ServletConfig) from GenericServlet which stores ServletConfig and calls the init().Since init() is always called GenericServlet defines dummy init() too. When you override init() your implementation will be called from the other one init(ServletConfig)
{ This info is taken from Inside Servlets , Dustin Callaway }
2. Yes, when you call ServletContext.getInitParameter() you will get the params that you defined there .
If you use the ServletConfig.getInitParameter you will get the ones that you defined in between <servlet></servlet> tags.
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Got it ersin
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic