【正文】
sing a Java class. The dynamic form beans are treated like Hashtable objects with strongly typed objects for values. As for action mappings, the ability to specify a tile as a target was a pletely logical addition once the decision was made to incorporate the Tiles library into the Struts distribution. You can see the tile targets ( and ) in the action mapping for the profile form. The tiles are specified in the input attribute and the path attribute. Note that the ability to specify a tile target remedies the problem of changing filenames and locations 6 mentioned in my analysis of the pagecentric model: tile targets are virtual or logical names rather than physical names. Tiles are specified in definition/ tags. You can name the definitions anything you want, and the name attribute does not have to be a substring match of the path attribute. I have chosen the name rootLayout for the first definition to indicate that it is the base layout that pages in the application will follow. Note the path: /tileslayout/. If you look at /tileslayout/ under EX2_INSTALL/src/web, you will see how simple and clean the layout is. A user interface designer would love it. Note also that it contains no code, so the user interface designer can make changes without worrying about breaking anything. The tiles:insert/ tags in correspond to the put/ tags within the rootLayout definition in . Note that the tiles:insert attribute=x/ tags each have an attribute representing a logical name. Each logical name maps to a name and value specified using a put name=x value=y/ tag in the definition/ tag within . By using logical rather than physical names in the page and by consolidating physical names in , we make changes to filenames and project filesystem organization manageable. The real savings in time and the most significant increase in adaptability es with inheritance of layouts, another Struts feature. In , the section below the Page definitions banner has two pages: and . The names are arbitrary and you don39。s going on here? There are a lot more files. As with mosttechnologies that impose more order and structure, with Struts and Tiles there is a startup cost in the form of administrative files. For a small project of a few pages, this additional overhead may not make sense. As the project grows, however, the Struts and Tiles approach really begins to shine. Let39。 see the Tomcat documentation to resolve the issue. Hello, World: A first attempt To take a look at our first example, follow these steps: Change to the EX1_INSTALL directory. Edit the file and fill in an appropriate value for . The value can either be an absolute or a relative path, although if you are inexperienced with how Ant works, it is probably best to use an absolute path. Type ant deploy. This will build the first example application into a WAR file ready for deployment, then deploy it to Tomcat. If you get an error indicating that Ant could not be found, see step 3 in the “ Installing Struts and Tiles” section and make certain that Ant is in your path. Point your Web browser to You should see a Hello, World page. The Example 1 Web application is a very simple illustration of mon Web application functionality. All but the simplest of applications require a consistent user interface from page to page. Usually this means that all pages have a mon logo, 4 top banner, top or left navigation bar, body, and footer. In Example 1, I have purposely hardcoded the mon items in each page to demonstrate a point. Beginners at Web application development typically add new pages of functionality by copying and pasting existing code into new documents. It is easy to see how this approach can quickly bee unwieldy. With every addition, the process of changing mon page elements, such as a menu or a logo, takes longer and is more prone to error. Clearly, the copyandpaste approach is a terrible model for any application that will grow beyond a few pages. Astute readers will realize that JSP technology provides functionality to include content from other servlets and pages. Why don39。 it demonstrates the pagecentric approach. By paring it with Example 2, you39。s sample code. Once you39。s sake, I will discuss only changes and Struts topics that he didn39。ll find it difficult to route control from one page to another in a way that preserves manageability down the road when the code needs to be changed again. Do you place step 4 in the same page as step 3? If you use separate JSP pages, how do you keep track of which pages link to others, and what do you do when you want to change a page39。 1 Struts and Tiles aid ponentbased development In 1994, when mainstream adoption of Web application development had only just begun. Because of the immaturity of the Web, developers had few tools to help them build Web software. As a result, applications mixed HTML code with application logic in ad hoc solutions. Understandably, UI design changes and business logic updates were both difficult and expensive in large applications because the tightly coupled presentation and logic obfuscated both elements, leading to errors and slow progress. Also, the mixed code necessitated knowledge of UI design on the part of developers or a close working relationship between developer and graphic designer that often made for inefficient use of time. The introduction of JSP technology and tags ameliorated the change problem somewhat because logic and display could be separated. UI designers could productively work on display while developers could focus on logic. However, this approach still suffered shortings. Notably, certain operations mon ones, too were still hard to develop. The validating form is the classic exa