Multiple choice technology programming languages

Which of these is a correct example of specifying a listener element resented by MyClass class. Assume myServlet element is defined correctly. Select the one correct answer.

  1. <listener>MyClass</listener>

  2. <listener> <listener-class>MyClass</listener-class></listener>

  3. <listener> <listener-name>aListener</listener-name> <listener-class>MyClass</listener-class> </listener>

  4. <listener> <servlet-name>myServlet</servlet-name> <listener-class>MyClass</listener-class> </listener>

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

The listener element in web.xml must contain a listener-class subelement specifying the fully-qualified class name of the listener class. Option A is missing the listener-class wrapper. Option C incorrectly includes listener-name (which is not a valid element). Option D incorrectly references servlet-name (listeners are not tied to specific servlets). Only option B shows the correct structure.