• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet doubt

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can i call a destroy()in doGet() explicitly?

I tried to call the init() from doGet() it works fine but when iam trying to call destroy() explicitly it is giving the nullpointer exception.

May i know the reason?
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For your First quetion:

init(),service(),destroy() are container callback methods and you should never call those.

But Of course yes, you can call those methods. Because servlet is also a class and it follows normal Java class rules.

For Second Question:

It looks strange to me. can you post your servlet class?
 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[BPSouther: Added UBB Code Tags]
[ November 16, 2006: Message edited by: Ben Souther ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
trinadh reddy,

You would do well to read through the Servlet Spec; especially the sections on the "Servlet Lifecycle". (link in my signature)

You don't instanciate servlets with the new keyword.
The container does this for you.

Also, as Prabhu venkatachalam has mentioned, the methods listed above are call back methods. In other words, they are placeholders for your code. The container calls these methods at the appropriate time, You don't call them yourself.
You can override the init and destroy methods and add any code that you want to have run at startup and shutdown.
Do not override the service method directly.
Instead override doGet or doPost.
 
reply
    Bookmark Topic Watch Topic
  • New Topic