This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes How does servlet decide which init method to call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How does servlet decide which init method to call" Watch "How does servlet decide which init method to call" New topic
Author

How does servlet decide which init method to call

Satish Kota
Ranch Hand

Joined: Feb 08, 2006
Posts: 88
If i have a servlet which overrides both init() and init(ServletConfig) method. How does ServletContainer decide which init method to call?


SCJP 5.0 77%
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
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).


Ping & DNS - my free Android networking tools app
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Satish Kota:
If i have a servlet which overrides both init() and init(ServletConfig) method.


Why would you do that?


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Also, the Javadoc descriptions describe how each will be used. The Javadoc is your friend.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How does servlet decide which init method to call