• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overloading of init-service and destroy methods

 
devayani Devasthali
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello All,
I am writing simple servlets .can anybody pls help in understanding the concepts?
Please correct me wherever I am wrong.
thanx in advance
actually, I have overrided init , service and destroy
now doGet will not be called automatically hence I called that explicitly inside service..
now inside service , first I have called destroy method then doget ()
logically, either I must get exception or it should not called doGet method once servlet's destroy method is called.
but practically,called both service - destroy and then doget method ...
can anybody pls clear my doubt ?
am I going wrong somewhere?
pls do reply asap.
thanx & regards
Devayani
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should never call destroy, just like you should never call init. The servlet container calls these when a servlet is created or removed. Apart from that it sounds OK.
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you call destroy() from service() method it becomes just an ordinary method call. It wont really unload the servlet, it will be only unloaded when the destroy method called by servlet contained and we wont have control on when it need to be unloaded.

You should never call destroy or init methods.
[ February 15, 2006: Message edited by: KJ Reddy ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to read up on the service method as well.
There is generally never a need to override it when doing normal application coding with Servlets.

In short the service method, analyses the request and calls the appropriate method (doPost, doGet, doHead, etc...) depending on type of the request. Overriding it short circuts this process.
 
Bruno Boehr
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
devayani Dev,

In addition to what the previous commenters have said, I would suggest that you describe your situation and tell us what effect you are trying to achieve by calling the destroy() method from inside service(). Chances are, a better solution might pop up
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you need also play with java itself a bit. For some reason you have impression that when you call some methods of your class, all other classes can notice that. For example if you define a method with name flyGrog and call it, you will surprise that no flying frogs happen after.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic