• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

servlet initialization

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Any body can tell me where the servlet is initialized (in the constructor or the init() method).Thanks in advance.
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That depends on what exactly you mean by initialization. After the constructor has been run, the object is ready to be used; so it is initialized as far as the JVM is concerned. But the developer may have put some initialization code in the init method; so as far as he is concerned, the servlet would not be initialized until init has been called.
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi...
From the "servlet life cycle" perspective the following two phases are different;

1. Construction: in this phase the container merely creates an instance of your "class" by calling the constructor.
2. Initialization: here where the container grants the created instance the priviliges and benefits of becoming a servlet, and this take place in the init() method.

You may add some code in your contrctor to initalize the created instance, but you will not be able to access any servlet features as they the instance is not initalized yet.

Hatim
 
Abhishek Kumar Singh
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Ulf...that's exactly the reason why there is an init() method in a servlet's life cycle...
 
reply
    Bookmark Topic Watch Topic
  • New Topic