File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes  init() method ........ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark " init() method ........" Watch " init() method ........" New topic
Author

init() method ........

eswar kumar
Ranch Hand

Joined: Oct 20, 2002
Posts: 98
can i call servlet init() method from sevlet service() method ?
share with me
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
The EJB certification exam does not deal with servlets.
Therefore, I'm moving this thread to the Servlets forum where you might get more answers. Thank you


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
There is nothing to stop you calling init() from service(), but one has to wonder why you would want to do so.
If you expect your servlet might be subclassed (particularly by a different developer) in the future, it would be wise to avoid calling init() from service() because this would surprise them and perhaps cause bugs.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
deepak kukreja
Ranch Hand

Joined: Aug 13, 2001
Posts: 54
init() is used by the servlet container for initializing a servlet.
Even if u call it in ur code it won't do 'nething for you.


Deepak<br />SCJP
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Even if u call it in ur code it won't do 'nething for you.

It will do whatever is coded in it, no? You might want a servlet to re-read configuration from a file or refresh a cache from the database so you don't have to stop and restart the server to affect changes. Even so, I'd make a method with a more meaningful name like loadFooCache() and call it from init() and from the refresh() call.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: init() method ........