• Post Reply Bookmark Topic Watch Topic
  • New Topic

ContextListener  RSS feed

 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two servlets TestServlet and TestServlet2 in a web-app along with a <listenter>LifecycleListener</listener> defined in web.xml. Also both servlets are configured to load on startup. It seems like only one instance of the listenter instance is created.
What is the life cycle of a web-app listener. One instance for all the servlets? Thanks.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Define in web.xml
<listener>
<listener-class>TestServlet1</listener-class>
</listener>
<listener>
<listener-class>TestServlet2</listener-class>
</listener>

//javax.servlet.ServletContextListener interface is notified when web application is initialed or destroyed in container
***you remeber :
one context per web application per JVM
 
Tom Wolve
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
the web server creates one instance per <listener-class> included in the web.xml.
According to the servlet specifications the instantiation process has to be completed prior to executing the first request for the application.
Also, the container must maintain a handle to the listener until the last request is made.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!