This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with ServletContextListener  RSS feed

 
Lanka Prasad
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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 ]
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • 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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you having trouble; compiling or running?
 
Lanka Prasad
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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!")
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!