aspose file tools*
The moose likes Servlets and the fly likes difference  work of between init() and constructor? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

difference work of between init() and constructor?

munjal upadhyay
Ranch Hand

Joined: Sep 18, 2010
Posts: 69

I have read the headFirst jsp and servlet
but still not clear about this ....



Prashant Chindhade
Ranch Hand

Joined: Jan 19, 2011
Posts: 77
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

Joined: Oct 02, 2009
Posts: 21

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.


SCJP 6 | OCPJWCD6
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61415
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference work of between init() and constructor?