HttpSessionAttributeListener getAttribute vs getValue

Posted on 2013-09-16
Medium Priority
Last Modified: 2013-10-01

I am reading about  HttpSessionAttributeListener as follows

attributeAdded method called when a new attribute name is first added to a session.
attributeReplaced method called when a new value is assigned to an existing name. attributeAdded is not called in this case.
To obtain old value use event.getValue and to obtain new value is use session.getAttribute.

In my ListenerDemo class  method I only see getValue() but do not see getAttribute()

      public void attributeAdded(ServletContextAttributeEvent arg0) {
            System.out.println("Attribute Added");
            System.out.println("old"+arg0.getValue()); (i wasable to see getAttribute on arg0)

                      System.out.println("new"+arg0.getAttribute()); (not able to see getAttribute on arg0???)


I wonder what it mean by old value and new value and why we need to get old value.

when and why we use HttpSessionAttributeListener in practical applications.

Please advise.

Any links resources ideas highly appreciated. Thanks in advance
Question by:gudii9
1 Comment
LVL 36

Accepted Solution

girionis earned 2000 total points
ID: 39499065
System.out.println("new"+arg0.getAttribute()); (not able to see getAttribute on arg0???)
You need to use session.getAttribute. The ServletContextAttributeEvent does not have a getAttribute method.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question