3. Obtain references to the attribute name, attribute value, and
servlet context. The attributeReplaced method calls getName
and getValue on its ServletContextAttributeEvent argument
to obtain the name and value of the modified attribute. The
method also calls getServletContext on its argument to get a
reference to the servlet context.
4. Use the objects. The attribute name is compared to "company-
Name". If the name matches, the attribute value is used as the new
value of the formerCompanyName servlet context attribute.
5. Declare the listener. The listener is declared in the deployment
descriptor with the listener and listener-class elements, as
shown here:
coreservlets.listeners.ChangedCompanyNameListener
The web.xml file is shown in Listing 6.6.
Listing 6.7 presents a JSP page containing a form that displays the current company
name, lets users enter a new name, and submits the new name to the Change-
CompanyName servlet (Listing 6.8). Because changing the company name is a
privileged operation, access to the form and the servlet should be restricted.
So, the form is placed in the admin directory and the servlet and servletmapping
elements are used to assign the servlet a URL that also starts with /admin.
See Section 2.4 (Assigning Names and Custom URLs) for details on servlet and
servlet-mapping; see the deployment descriptor in Listing 6.
Pages:
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333