• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic