File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes call super.init(config)... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "call super.init(config)..." Watch "call super.init(config)..." New topic

call super.init(config)...

Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
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?

ersin eser
Ranch Hand

Joined: Feb 22, 2001
Posts: 1072
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

Joined: Dec 12, 2001
Posts: 291
Thanks Got it ersin
I agree. Here's the link:
subject: call super.init(config)...
It's not a secret anymore!