This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Calling init 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 "Calling init" Watch "Calling init" New topic
Author

Calling init

Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
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


Malhar Barai
SOA & Java Book
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
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.


Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
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 ]

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
wood burning stoves
 
subject: Calling init
 
Similar Threads
loading of static attributtes
Calling init()
Init and Constructor
init methods of Servlets: need clarification
ServletA extend ServletB right or wrong ?