• 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

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

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can i call servlet init() method from sevlet service() method ?
share with me
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
reply
    Bookmark Topic Watch Topic
  • New Topic