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

difference work of between init() and constructor?

 
Ranch Hand
Posts: 69
Mac OS X Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I have read the headFirst jsp and servlet
but still not clear about this ....



 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
The constructor is called by the container simply to create a POJO (plain old java object).

init method is the method which is invoked when servlet in called and it adds values to the servlet context so its a very much difference between constructor and init method...

regs

Prashant
 
Greenhorn
Posts: 22
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

prashant chindhade wrote:The constructor is called by the container simply to create a POJO (plain old java object).

init method is the method which is invoked when servlet in called and it adds values to the servlet context so its a very much difference between constructor and init method...

regs

Prashant



It's not when the servlet is called but initialized. And it happens only once, as I told you in a different thread.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
The init() method is used to initialize a servlet as it has access to the ServletConfig instance while the constructor does not. This has been asked many tomes before. Please SearchFirst before posting.
 
    Bookmark Topic Watch Topic
  • New Topic