File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
    Bookmark Topic Watch Topic
  • New Topic

difference work of between init() and constructor?

 
munjal upadhyay
Ranch Hand
Posts: 69
Java Mac OS X Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have read the headFirst jsp and servlet
but still not clear about this ....



 
Prashant Chindhade
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Mac Luq
Greenhorn
Posts: 22
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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