SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 368 | Next

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"

36
web.xml (Excerpt for StopRequestCounter
listener) (continued)
Chapter 6 ?–  The Application Events Framework 326
cooperate: a ServletContextListener to set up application-wide information
about the session attributes that store daily specials, a ServletContext-
AttributeListener to monitor changes to the attributes that store the information,
and an HttpSessionAttributeListener to keep a running count of
orders for the daily special.
The three listeners are described in more detail in the following subsections.
Tracking Orders for the Daily Special
As the first step in creating an order-tracking system, you need a servlet context listener
to read initialization parameters that specify which session attributes correspond
to orders and which items are the current daily specials. These values should
be stored in the servlet context so other resources can determine what the daily specials
are. Listing 6.37 shows this listener.
Second, you need a session attribute listener to keep a running count of orders for
the daily special. The count will be incremented every time a designated attribute
name is added with any of the daily specials as its value. The count will be decremented
every time a designated attribute is replaced or removed and the previous
value is one of the daily specials. Listing 6.38 shows this listener.
Listing 6.39 shows the deployment descriptor that registers the two listeners and
sets up the servlet context initialization parameters that designate the names of
order-related session attributes and the names of the daily specials.


Pages:
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380