This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

init() method in servlet

 
T sandya
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
May know the reason why init()method is that much important,if we have the constructor.And can i write the destroy() inside init() method.

please clarify me on these two questions.

thanks and regards,
sandya.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
like here?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13047
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can i write the destroy()

Why don't you go download the servlet API document and read about the intended use of all of the servlet methods instead of these piecemeal questions?
This is a good starting point.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If everybody promise that they will provide a constructor with a parameter �ServletConfig� while creating a servlet then they might remove this method (not sure though).


How can you get the 'ServletConfig� in the construstor.It is possible only after the servlet is instantiated.

You can use the construstor though.. if you do not want to access and the 'ServletConfig� and may be define and initialise just the instance variables.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As already discussed servletConfig is not available in the constructor so init would be the right place to initialize.You you want to initialize something which is not dependent of context of servlet config then you can do that as well in the constructor (its not a preferred way of doing thogh)

destroy() is a callback method called by the container .. you can explictly call that but in that case that is just like any other method in the class ..no use..destroy is called by the container when its about you destroy the servlet (for running some code for cleaning )..

its something like overriding the finalize (in Object class)method and calling that with the hope that this would garbage collect the object.
 
anil borude
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But What is basic Difference between Constrctor() & Init() mthod ?

Regards.
Anil Borude
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
constructor is called while creating a object (its actually not a method) and init is a method ..A callback method called by the container after the constructor is called and it has servletConfig's reference.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic