Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

init()

 
Ankitt Gupta
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ramnna jain
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic