Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Servlet-Context-Event

 
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the method :
public void contextInitialized(ServletContextEvent event){....}

What calls this method ?
What passes a reference of type ServletContextEvent to the above method and why ?
What is the task performed an object of type : ServletContextEvent ?


 
Greenhorn
Posts: 15
Eclipse IDE Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What calls this method ?
What passes a reference of type ServletContextEvent to the above method and why ?



Container calls this method when your web app is deployed, provided that the listener is configured properly in the DD or via annotations. And it sends the ServletContextEvent object as an argument to this method for two reasons

1. To indicate that the event of context iniatilization has occured so that you can run some code before the rest of the app starts servicing a client.

2. To provide access to the ServletContext object via the getServletContext() method. Now you got your ServletContext object and you can do a lot of things with that. you can get context init params. you can obtain a Database connection and store it as an attribute in the context scope, so that the rest of the app can use it.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic