wood burning stoves*
The moose likes Servlets and the fly likes init() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "init()" Watch "init()" New topic
Author

init()

Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
At first container loads the servlet class.Then the no-arg constructor of the servlet runs creating a servlet instance.Then the container calls the init() method on servlet instance.
My doubt is that if there is init parameter in the DD which method will be called init() or init(servlet config) or both.
And does exact similar thing happens in JSP also?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42371
    
  64
The servlet container only calls methods that are part of the Servlet interface. But you should read the javadocs of the two GenericServlet.init methods.


Ping & DNS - my free Android networking tools app
ramnna jain
Ranch Hand

Joined: Mar 16, 2009
Posts: 129

Hi! Ankitt,

I am new for web application development, but I would like to share what I know:

Container stores the context-param into to ServletContext object &
then ServletConfig receives the reference to ServletContext.

If there are init-param in the DD then they are stored in the ServletConfig &
now this ServletConfig object is passed to init(ServletConfig).

init() is some thing which gives a chance to a programmer to initialize what he want for his/her servlet.
not compulsory to override.

If you override the init() then init(servletconfig) calls your init() implementation.

The init(servletconfig) is called as soon the servlet instance is created, but before service method is called.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: init()