• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet loading and servlet instacne

 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know when is servlet instance created? I mean is it when the container sees a request for a particular servlet , and then the instance for that servlet is created?

Also when does the container loads the servlet class?
 
Prabhat Gupta
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess the followings happen when a request come for particular servlet.

1.Container see whether the instance of that servlet is already present or not.if yes then simply assign a new thread for that request.
2.if not,i.e very first request for that servlet. Container loads that servlet class.
3.Calls the no arg constructor for that servlet class.
4.Now it is time to initialize some init parameter. hence it calls the init() method of servlet class.
5. Finally calls the service() method to serve the request.

If i am wrong please rectify me.

Prabhat
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic