• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling init

 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Well "init is called only once when the servlet is requested for the first time."
What would happen if I again call the init() in service(...) or doGet(..) or any other method.
Tia
MB
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then it gets called each time your code is executed.
some people will tell you this is a bad idea, but under some circumstances i believe it is the best solution.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't imagine any situation it would make sense for your code to call init. I can imagine plenty of situations where your code would want to do the same processing at several points, though. If that's the case, just delegate from init and your code to the same method:

[ December 09, 2003: Message edited by: Frank Carver ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65128
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm with Frank. Calling init from elsewhere in the servlet is a non-standard and unexpected thing to do. Factoring common behavior into a private method is much cleaner.
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic