Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Init and Constructor

 
Padma NI
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is first invoked when a servlet is fist called? Init or constructor? and why do we need to register servlet with diferent names and have different instances?
 
srinivas madugula
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai,
init is not a static method. so it cannot be called with out creating an instance. to creat an instance you must use constructor.
i dont know why you asked this question.
bye
have a good one
 
ramu velagaturi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
init method is first called
 
Panagiotis Varlagas
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
init() is an instance method. This means that, in order for the servlet to invoke init() it needs to have an instance of your servlet.
aServlet.init();
In order to have a instance of your servlet, the servlet container needs to have executed an statement which might look like this:
aServlet = new YourServlet();
I.e. the constructor gets executed first.
Morale of the story: Brush up on your Java fundas!
[ June 20, 2003: Message edited by: Panagiotis Varlagas ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic