permaculture playing cards*
The moose likes Servlets and the fly likes Difference between init() and init(ServletConfig config) methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Difference between init() and init(ServletConfig config) methods" Watch "Difference between init() and init(ServletConfig config) methods" New topic
Author

Difference between init() and init(ServletConfig config) methods

Rajpal Kandhari
Ranch Hand

Joined: Aug 26, 2000
Posts: 126
Hello Friends,
I am till date was using init(SertvletConfig config) method for servlet initialization. Well this method is overloaded and it has no arguments. Thai is init(). Can any one tell me where to use the other init method and what is the diff between the two.
Thanks,
Regards,
Raj.


Regards,<P>Raj.<BR>-------------------------<BR>Afforts should be Appriciated.<BR>-------------------------
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
The init() method is provided as a convenience method in the GenericServlet class. GenericServlet has an
init(ServletConfig conf ) method as required by the Servlet interface. If you don't override init(ServletConfig conf), then the GenericServlet method will be called - it in turn calls the init() method.
So which one to choose is up to you. Personally I prefer to override init( ServletConfig conf) because it makes clear what is happening and because I usually need to retrieve init parameters from the ServletConfig anyway.
Bill

------------------
author of:
Travis Gibson
Ranch Hand

Joined: Oct 17, 2000
Posts: 100
Bill,
You are the author of several well known books, so I reckoned you would probably be a good source to ask a couple of very common questions to.
1.) What's the best way to break into Java development?
Note: I already have my SCJP
2.) What area(s) of Java do you see demand being the highest in
the near future(Next two years).
Regards,
Travis M. Gibson
SCJP

Regards,<BR>Travis M. Gibson, SCJP<BR>Java Developer<BR>www.travismgibson.com<BR>travis@travismgibson.com
Rajpal Kandhari
Ranch Hand

Joined: Aug 26, 2000
Posts: 126
William,
thanks for you're explanation on init(0 and init(ServletConfig config) method. I would like you to see the posting in th same forum thread title "Pl help me with this href portion in this code Dipanjan Paul 5 November 27, 2000 11:39 AM "

Here Paul was using init() method and was not able to access his database and was getting NullPointerException. When i changed the method it worked fine....Why like this....pls explain me what was going in the two cases. Why it didn't worked for init() method.
Regards,
Raj.
 
wood burning stoves
 
subject: Difference between init() and init(ServletConfig config) methods
 
Similar Threads
difference b/w init() and init( config)
init method of Servlet
doubt in servlet init method
init() method usage
RequestDispatcher