Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confusion in init() and init(ServletConfig)

 
Prasad Shindikar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could somebody tell me the flow in which these two functions are called while servlet initialization ?
It would be helpful to know, right from a servlet constructor running, how does the container call different methods (like init()) before calling the service() method to run the user requests.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refer to this FAQ
 
Pawanpreet Singh
Ranch Hand
Posts: 264
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prasad,

If you look at javax.servlet.Servlet interface
init(ServletConfig) is declared that is implemented by GenericServlet.

Following are the steps of servlet invocation:
1. Loading of servlet class
2. Create instance of servlet
3. Create ServletConfig and ServletContext
4. Before calling init(ServletConfig), container will call init() method and get ServletConfig by calling getServletConfig() method[which is in javax.servlet.Servlet and implemented in GenericServlet] and then it calls init(ServletConfig) method.
 
Prasad Shindikar
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks both of you. i got it!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic