• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet Constructor

 
Manish Kumar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

If anybody can halp me with my question.If we already had constructor in Servlets then why we needed Init() method for initialization.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The init method is all about the initialization parameters.

A Servlet is interesting not because of the fact that it is a servlet, but because of the fact that it can be initalized with a unique set of parameters, as defined in the web.xml file. You can't access the initialized, InitParameters in the constructor, but you can in the init method. This is really the key.

A Servlet isn't a Servlet just because it has a constructor. It isn't a Servlet until it is also described as a Servlet in the web.xml file. It's like the Sperm and the Egg - the two really have to go together to get some life out of your code (the web container is the ovary, I guess). Init gives you access to the merging of the web.xml and the Java code.

-Cameron McKenzie
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!