4. Use the objects. If the attribute retrieved in Step 3 is equal to stats,
we call RequestCounter.setCountingFinished(true) to
prevent further data collection.
Chapter 6 ?– The Application Events Framework 324
5. Declare the listener. Listing 6.36 shows the web.xml file. It declares
the listener with the listener and listener-class elements.
Listing 6.35 StopRequestCounter.java
package coreservlets.listeners;
import javax.servlet.*;
/** Listener that looks for 'stats' as the added attribute
* to the request scope. If such an attribute is added, it
* signals RequestCounter to stop collecting request
* frequency data.
*/
public class StopRequestCounter
implements ServletRequestAttributeListener {
/** If the attribute added to the request scope is "stats",
* signal to the ServletRequestListener to stop recording
* request statistics.
*/
public void attributeAdded(ServletRequestAttributeEvent event) {
String attributeName = event.getName();
if (attributeName.equals("stats")) {
RequestCounter.setCountingFinished(true);
}
}
public void attributeRemoved(ServletRequestAttributeEvent event)
{}
public void
attributeReplaced(ServletRequestAttributeEvent event)
{}
}
Listing 6.36
web.xml (Excerpt for StopRequestCounter
listener)
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://java.
Pages:
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378