Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does servlet decide which init method to call

 
Satish Kota
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i have a servlet which overrides both init() and init(ServletConfig) method. How does ServletContainer decide which init method to call?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the javadocs for the Servlet interface, you'll find only init(ServletConfig), so that's what the container will call. It can't assume that there will be an init() method (a servlet doesn't need to extend GenericServlet or HttpServlet, after all).
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satish Kota:
If i have a servlet which overrides both init() and init(ServletConfig) method.


Why would you do that?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, the Javadoc descriptions describe how each will be used. The Javadoc is your friend.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic