Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

init() method  RSS feed

 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have problem to understand with init() method that takes ServletConfig as argument and the init() method that doesn't take argument. What i don't understand, in both cases i can access my parameter in my web.xml file as follow :
public void init() throws ServletException {
String msg= getServletConfig().getInitParameter("message");
}

Why do we define the init() method with ServletConfig as argument if we can access parameter with the init method without Servletconfig as argument ? what is the interest ? (Any explanation 'step by step' would be appreciated)
Thanks a lot.
 
David Carew
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The web.container will call init(ServletConfig). If you override this method (it's in the class GenericServlet) then you have to call super.init(ServletConfig) to guarantee that the web container will initialize your servlet properly.
init() is a convenience method called by GenericServlet.init(ServletConfig). If you override this then you don't have to call any of the superclass methods to guarantee that your servlet will be initialized correctly and as you pointed out, you still will have access to the ServletConfig instance.
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David thank you for your reply.
Now i understand better the interest.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!