Forums Register Login

Servlet-Context-Event

+Pie Number of slices to send: Send
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 ?


1
+Pie Number of slices to send: Send
 

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.

Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1446 times.
Similar Threads
how-to call some servlet or bean when war is loaded
static variable for Timer ?
how we can get notification of an event listener at web browser
James embedding
Abort startup duing Loading Errors
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:25:09.