Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

why why HttpSessionBindingListener method didn't trigger?  RSS feed

 
deng shuangyi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My JDK version is 1.5,use tomcat5.5 as contianer.
When I start tomcat "contextInitialized(ServletContextEvent)" print.But when I add a value to session (request.getSession().getAttribute("userName","deng") ,the valuebound method didn't trigger.

I don't know why? please give me a help?

this is my web.xml configuration:




this is implements class :


[ August 29, 2007: Message edited by: deng shuangyi ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the API for SessionBindingListener:

Causes an object to be notified when it is bound to or unbound from a session. The object is notified by an HttpSessionBindingEvent object. This may be as a result of a servlet programmer explicitly unbinding an attribute from a session, due to a session being invalidated, or due to a session timing out.


http://java.sun.com/j2ee/1.4/docs/api/index.html

Notice the word "it" is in bold.
 
Sylven Yip
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.request.getSession().setAttribute("userName","deng");
set,not get!

2.you don't need to add the HttpSessionBindingListener class to web.xml configuration.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sylven
Please read carefully what Ben has posted, he has highlighted "it"
Which means, suppose you have a class MyAttribute implementing HttpSessionBindingListener and you do something like

session.setAttribute("MyAttriute",new MyAttribute());
Then the listener will be notified.

Yes you need not declate HttpSessionBindingListener in web.xml
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!