• 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 Constructor

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic