Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Listeners and Distributed JVMs

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi-
I am not at all able to understand the difference between HttpSessionAttributeListener and HttpSessionBindingListener. Pls can someone help me with this.
Also I understand that all JVMs in a distributed environment have their own copy of the ServletContexts and HttpSessions. If so, then how can we share any attribute if we want to ? In case we don't use an external resource (like database), do we have to manually replicate the attribute across all the sessions ?
Thanks, Sudd
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not at all able to understand the difference between HttpSessionAttributeListener and HttpSessionBindingListener. Pls can someone help me with this.
Hi Sudd
HttpSessionAttributeListener : configured in web.xml
HttpSessionBindingListener : not configured in web.xml
HttpSessionAttributeListener : This listener interface can be implemented in order to get notifications of changes to the attribute lists of sessions within this web application.
HttpSessionBindingListener : Object gets notified when it gets bound or unbound
all JVMs in a distributed environment have their own copy of the ServletContexts and HttpSessions.
Ans : Yes
see sharing an attribuute in disturbted will not work for servlet context OR session b'coz they are local to jvm for sharing an attributes better u need to make use of rdbms Or any external source.
see sharing a parameter u can do it by configuring in web.xml b'xoz parameter u defined in context-param that is available to all the servlet context but sharing is not the right word i feel
correct me if i am missing something
Rishi
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps more simply---
A HttpSessionBindingListener wants answers to the question "Am I being bound in or removed from a HttpSession?"
A HttpSessionAttributeListener wants answers to the question "Is something being bound in or removed from a HttpSession?"
In a distributed container, the HttpSession objects and all their attributes are shared between JVMs (although each one is usually only active on one JVM at a time). Everything else exists strictly on a per-JVM basis.
- Peter
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
When u say "session.setAttribute("myObject", JavaObject)", then the object implementing the HttpSessionAttributeListener is called, similarly for session.removeValue("myobject").
In the above if you want the "JavaObject" to be notified then you make the "JavaObject" class implement HttpSessionBindingListner
HTH
Hari
 
Sudd Ghosh
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the explanation.
Sudd
 
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
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
    Bookmark Topic Watch Topic
  • New Topic