File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet constructor & init method

 
manish ahuja
Ranch Hand
Posts: 312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have read a lot on this topic in the forums but never got a conclusive answer.

Say I have some initialization functionality. Say i decide to initialize the same in the servlet's no args constructor instead of the regular init method. Both are called only once during the life time of the servlet.

So whats the advantage of having all inside a init method.
To be precise what i want to know what were the perils of the no args (not parameterized)servlet constructor approach which caused the creators of servlets to resort to the init method approach.

Is there some handshake between the container & the init method which is not in the case of servlet's no arg constructor

Do ellaborate a bit

Bye
Manish
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is guarenteed that the servletConfig instance is set up when the init() method is called.

When it comes down to it, it's always best to do things in the standard manner. Just because you might seem to be able to get away with something like setting up in a constructor, that's no guarentee that things won't break later when an underlying assumption changes.

It's your foot; you can choose whether to shoot at it or not.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic