• 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

Problem with ServletContextListener

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am ahaving a problem with ServletContextListener.
See the following code. Is there anything wrong with it.


web.xml is:


servlet uses this as :
B b = (B)getServletContext().getAttribute("ax");

I'm using Tomcat 5.5.20 Server.
Please give me a clue or show me what was wrong with this.
Do I need to implement HttpSessionAttributeListener and HttpSessionListener also in A ?
-Lanka

[BSouther: Added UBB CODE tags]
[ March 21, 2007: Message edited by: Ben Souther ]
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing seems to be wrong.You have to devug this.Put some log statements in the contextInitialized() method to see whether this is getting called or not.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you having trouble; compiling or running?
 
Lanka Prasad
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This could be compiled w/o problem, but when I requesting it prints b == null in stdout of tomcat/logs.

servlet class code:



-Lanka
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Did you cut and paste this into Javaranch?
If so the misspelling of listener might be your problem.
 
Lanka Prasad
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ben,

Thank you very much. I also hardly found it after realizing that the listener was not registered at all.

Can this kind of mistake be traced with a tomcat log or with DTD validation ?
Thank you very much for your co-opreation.
-Lanka Prasad
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is probably something in your tomcat logs.

If you're using a logging package, you could add a simple debug line to your listener's events which can be silenced in production mode.

log.debug("ContextListener.contextInitialized called!")
 
reply
    Bookmark Topic Watch Topic
  • New Topic