Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet-Context-Event

 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • 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 ?


 
Ashok Kurakula
Greenhorn
Posts: 15
Eclipse IDE Java Tomcat Server
  • 1
  • Mark post as helpful
  • send pies
  • 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.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic