File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Servlet-Context-Event" Watch "Servlet-Context-Event" New topic
Author

Servlet-Context-Event

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
Greenhorn

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: http://aspose.com/file-tools
 
subject: Servlet-Context-Event