Multiple choice technology web technology

A class wants to keep track of its number of objects being added to HttpSession objects. Which will be the ideal way to achieve this?

  1. Define a listener class implementing HttpSessionListener and whenever an object is added to Http Session object, keep track of the number of instances.

  2. Define a listener class implementing HttpSessionBindingListener and in the valueBound() method, keep track of the number of instances being added in a static variable.

  3. It is highly impossible to keep track the number of objects being added to a Http Session in a Web Application.

  4. The Servlet API provides direct support for keeping track the object instances.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

HttpSessionBindingListener is specifically designed for objects to be notified when they are added/removed from a session. The valueBound() method is called when the object is added. HttpSessionListener tracks session lifecycle, not individual objects.