• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ContextListener

 
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic