Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rajpal Kandhari
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rajpal Kandhari
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic