Java web development using hibernate, jsp and servlets, 2007

Page 131

Enhancing the Controller

119

Try It http://bytesizebook.com/book/ch4/enhanced/Controller This application looks the same as the others, but it is now using a controller helper.

4.7

Libraries in NetBeans

JAR files are added to the Libraries folder of a NetBeans project. When the project is built, all the JAR files are copied into the corresponding lib directory of the web application structure.

4.7.1

Libraries

To add JAR files to your web application, follow these steps. 1. Download the JAR files to your computer. 2. From an open NetBeans project, right-click on the project name in the Projects tab. 3. Select Properties. 4. Select Libraries. 5. Click the Add Jar/Folder button. 6. Navigate to the directory where the downloaded JAR files are. 7. Select all the JAR files you want to include in the web application. Every JAR that is added to the Libraries folder will be added to the CLASSPATH variable, automatically.

4.8

Summary

From now on, all controllers will have a helper class to facilitate performing the controller’s tasks. All controller applications perform similar tasks. Some of these tasks use objects that are the same for all controllers; these objects can be stored in the base class. Other tasks require the details of the current application; these belong in the helper class. In this chapter, many of these common tasks were explored. There are tasks that are common to all controllers: creating a logger, eliminating hidden fields, automating the controller logic and filling the bean. These tasks have been implemented so that they do not access any of the individual data members of the bean, so they can be placed in the base class. All controller helpers that are extended from the base class will have access to these features. The base class has been placed in the shared package, so that all future controller helpers can have access to it. The tasks that require the knowledge of the current application are specifying the location of the JSPs and copying the data from one bean to another. The copyFromSession method is needed so that hidden fields can be eliminated; the data from the session must be copied into the current bean. These tasks were added to the controller helper.


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.