aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes why cant we make the servlet ready completly b4 init() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "why cant we make the servlet ready completly b4 init()" Watch "why cant we make the servlet ready completly b4 init()" New topic
Author

why cant we make the servlet ready completly b4 init()

kajal mukergi
Ranch Hand

Joined: Mar 22, 2007
Posts: 102
Hello friends

why can v make the servlet fully really b4 init() method....

as we have default constructor of sevlet so we can keep every thing what we can keep in init() method there and start the service directly


why we have wait for ---> constructor (default)
then ---> init() (why so important)
then ----> service


cant we got from

----->constructor (default)
then---> service() directly........



103 page HDFS book has this but i am not able to understand it...
pls help me out....
bye
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
Sudhakar, please UseRealWords. "v" and "b4" may be appropriate for text messaging, but not in a forum like this.


Ping & DNS - my free Android networking tools app
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi Sudhakar,

After constructor completes you get an servlet object not an object that
has servletness.After that only the object gets servletness. Sevlet receives
servletness after the constructor completes and container creates HttpRequest and HttpResponse objects for the servlet.


As you said, what is role of init(), because it is early to do some things in the constructor, and you don't have servletContext inside the constructor
and obviously why should it be provided until our servlet object has not
gotten the things it needs to have.

HFSJ:
The container calls init() on the servlet instance after the servlet instance is created but before the servlet can service any requests;

inside init() you can do following:
-->Think about Applets init() where we load images
--> Creating database connection pool that will be used throughout.
-->Loading data onto HashMap
etc..


Thanks,
[ June 07, 2007: Message edited by: Chandra Bhatt ]

cmbhatt
kajal mukergi
Ranch Hand

Joined: Mar 22, 2007
Posts: 102
Thank you chandra.....

and yes from now i willl... take care of not using short letter Mr Ulf
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: why cant we make the servlet ready completly b4 init()