Rakesh Juyal
Rakesh Juyal

Reputation: 36759

How to identify when my session variable is changed?

I am having a session variable whose value can be changed from java and from Jsp as well. Is it possible to detect when this variable's value is changed?

Upvotes: 0

Views: 497

Answers (2)

David Rabinowitz
David Rabinowitz

Reputation: 30448

You can implement the HttpSessionAttributeListener and you will get notification every time the value is replaced. Notice that in the following cases (which is highly not recommended) it won't work:

MyObject myobj = (MyObject)session.getAttribute("obj");
myobj.setValue(newValue);

Upvotes: 2

alphazero
alphazero

Reputation: 27224

Use an HttpSessionAttributeListener.

Upvotes: 1

Related Questions