• Post Reply 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

init()

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 129
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic