This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Servlets and the fly likes Listener started twice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Listener started twice" Watch "Listener started twice" New topic

Listener started twice

Jeff Schanhals

Joined: May 20, 2005
Posts: 2
I created a ServletContextListener yesterday to initialize a connection to a business object and make it available to the servlets. The listener is successfully started, however, the contextInitialized method is called twice (and the business object is then created twice). I'm running on TomCat 5.5. My web.xml is at the bottom of this post. Additionally, Eclipse is showing an error on the web.xml -

The error goes away if I take out the listener sections.

Any help on this would be appreciated.


Pedro Gongora

Joined: Oct 03, 2003
Posts: 17

the error you got is because of the order of the web.xml sections, the error message specifies the order in which the parser is expecting the sections.

You are writing the <listener> tags after the <resource-ref> tags while it sould be between <filter-mapping> and <servlet> tags.
Jeff Schanhals

Joined: May 20, 2005
Posts: 2
Thanks for the information on the order of the sections. That corrected the error.

However, I am still getting the listener initialized twice. The listeners code is as follows:

I agree. Here's the link:
subject: Listener started twice
It's not a secret anymore!