Home

 

Controller layer

The controller layer was implemented using two different strategies-one straightforward, the other more complex, but more applicable to a real world situation.

The application has a total of five servlets:

ListAccounts-Gets the list of accounts for one customer.

AccountDetails-Displays the account balance and the selection of operations: List transactions, deposit, withdraw, and transfer.

Logout-Invalidates the session data.

PerformTransaction-Performs the selected operation by calling the appropriate control action: ListTransactions, Deposit, Withdraw, or Transfer.

UpdateCustomer-Updates the customer information.

The first three servlets use a simple function call from the servlet to the model classes to implement their controller logic and then use the RequestDispatcher to forward control onto another JSP or HTML resource. The pattern used is shown in the sequence diagram in Figure | 3-9.

Figure 13-9 ListAccounts sequence diagram

PerformTransaction uses a different implementation pattern. It acts as a front controller, simply receiving the HTTP request and passing it to the appropriate control action object. These objects are responsible for carrying out the control of the application. Figure | 3-10 shows a sequence diagram for the list transaction operation from the account details page, including the function calls through PerformTransaction, the ListTransactionsCommand class, onto the model classes, and forwarding to the appropriate JSP.

Figure 13-10 PerformTransaction sequence diagram

The Struts framework provides a much more detailed implementation of this strategy and in a standardized way. Refer to Chapter | 5, Developing Web applications using Struts for more details.

Note: Action objects, or commands, are part of the Command design pattern. For more information, refer to Design Patterns: Elements of Reusable Object-Oriented Software in the bibliography.

ibm.com/redbooks