• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet doubt

 
trinadh reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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?
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator

[BPSouther: Added UBB Code Tags]
[ November 16, 2006: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic