Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

ServletContextListener declared in TLD

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am implementing the downloaded source code from Chapter 10 (The Application Events Framework) of Marty Hall's "more Servlets and JavaServer Pages." I'm using Tomcat 5.5.7. The initial example illustrating ServletContextListener works fine. But when I remove the declaration of the listener from web.xml to a tag library (company-name-taglib.tld, in the book's example), Tomcat is APPARENTLY not loading the listener or executing its contextInitialized() method. The .tld file is in WEB-INF. I am 99.9% sure my web.xml and .tld files are conforming (I'm certainly not getting any parse errors). And when I create my own analogous but extremely simple example declaring a ServletContextListener from a .tld rather than from the web.xml, it works fine. Has anyone tried Marty's examples? In any case, any hints as to what I should check?

I say APPARENTLY not loading/executing. It was first apparent simply from running the application (null values for attributes that the listener is supposed to initialize). When I try including a "hi it's me" system.out.println statement in the contextIntialized() code, I am finding it doesn't output to Tomcat's log, in this or any other case, though the same statements in my HttpSessionListener's do output to the log. Is this an expected result (system.out.println statements produce output for HttpSessionListener's but not ServletContextListener's) and, if so, why? I then tried writing out a physical file from within my contextInitialized() code instead, and that produces a file for all my ServletContextListener's except the case in point, which seems to confirm that that particular listener is not getting loaded/executed. So a secondary question is, what is the best way, at least in a Tomcat 5.x environment, for knowing that the listener is being loaded/executed (other than inferring this from the runtime results or from debugging via file output)?
 
Marshal
Posts: 67463
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting. I've never tried to add a listener to a TLD, but here's what the spec has to say:

A Container is required to locate all TLD files (see Section JSP.7.3.1 for details on how they are identified), read their listener elements, and treat the event listeners as extensions of those listed in web.xml.

The order in which the listeners are registered is undefined, but they are
registered before application start.



So, it should work.

If I get a chance, I'll play around this weekend with it and see what happens.
 
Bear Bibeault
Marshal
Posts: 67463
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, on re-reading your post. You are getting a listener to work -- just not the example you are trying to emulate?

Are any tags in the same TLD being loaded?
[ July 22, 2005: Message edited by: Bear Bibeault ]
 
Randy Gibbons
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Oh, on re-reading your post. You are getting a listener to work -- just not the example you are trying to emulate?

Are any tags in the same TLD being loaded?

[ July 22, 2005: Message edited by: Bear Bibeault ]



Yes, I did get a listener declared in a TLD to work, just not the example from Marty's book. That listener worked fine too, when declared in the web.xml. And yes, the tag declared in the same TLD is working.
[ July 22, 2005: Message edited by: Randy Gibbons ]
 
Normally trees don't drive trucks. Does this tiny ad have a license?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic