• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

call super.init(config)...

 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • 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
 
ersin eser
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Got it ersin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic