This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Servlet-Context-Event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Servlet-Context-Event" Watch "Servlet-Context-Event" New topic


Rahul Sudip Bose
Ranch Hand

Joined: Jan 21, 2011
Posts: 637

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 ?

SCJP 6. Learning more now.
Ashok Kurakula

Joined: May 16, 2011
Posts: 15

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.

OCPJP 6, OCE Java EE 6 JSP and Servlets Developer, OCE Java EE 6 EJB Developer...
I agree. Here's the link:
subject: Servlet-Context-Event
Similar Threads
James embedding
Abort startup duing Loading Errors
static variable for Timer ?
how-to call some servlet or bean when war is loaded
how we can get notification of an event listener at web browser