Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
HydraExpress Servlet Development Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

6.7 Implementing a Listener

The role of a listener is to receive an event and to act upon that event. A listener does not have access to a request object or a response object. A listener is typically stateless. Instead, a listener receives an event and responds to the event directly.

For example, a session listener can add a specific attribute to each session created within a context. The code sample below implements a listener that initializes each new session with an IsAdministrator attribute.

Line //1 extracts the new session from the session event. On Line //2, the listener constructs a new, empty rwsf::Attribute. The listener copies the value false into the attribute on line //3. Finally, on line //4, the listener adds the attribute to the session with the name IsAdministrator.

Creating the attribute in a session listener guarantees that every session in the context contains an IsAdministrator attribute which is initially false. Similar code could be included in each servlet in the application each time the servlet receives a new session. However, isolating the code in a listener simplifies the servlets.

Previous fileTop of DocumentContentsIndex pageNext file

©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.