JBridge

JBridge: Certification Question Of The Day

JBridge Home >> Certification Questions >> Question for Thursday May 22nd 2003 Thursday May 22nd 2003
Which of the following statements best describes the function of the ServletContextListener interface? (Choose 1 answer)

A It detects the start and close of a web application.
B It detects the initialisation and destruction of each servlet within a web application.
C It detects the addition, removal or change of attributes to the ServletContext.
D It detects the creation and invalidation of sessions.
Page down for the answer...











































The Answer

The correct answer is A: a ServletContextListener detects the start and close of a web application. Strictly speaking, it detects the initialization and destruction of the ServletContext. However, there is only one ServletContext per web application, initialized just after the web application starts and destroyed just before the web application closes. I rest my case, but feel free to challenge my assertion!
Answer B is wrong: servlets themselves have built-in methods to deal with their own initialisation and destruction.
Answer C is wrong: it is the ServletContextAttributeListener which listens for the addition, removal or change of attributes to the ServletContext.
And similarly, answer D is wrong, as there is an HttpSessionListener which detects the creation and destruction of HttpSessions.


EMail: dbridgewater@jbridge.co.uk
Phone: +44 (0)1943 877414
Fax: +44 (0)1943 877414
Mail: David Bridgewater, Willow Dene, Bradford Road, Menston, Ilkley, West Yorkshire, LS29 6ED, UK
Copyright © 2003 David Bridgewater. All rights reserved.