File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
kajal mukergi
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sudhakar, please UseRealWords. "v" and "b4" may be appropriate for text messaging, but not in a forum like this.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
kajal mukergi
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you chandra.....

and yes from now i willl... take care of not using short letter Mr Ulf
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic