Home

This Chapter
-Introduction
-Why Servlets Are Not Dead
-The Problems with Model 1
-Model 2
-The Benefits of Struts
-Overview of the Chapters
-Code Download
-Other Resources

Table of Contents
-Introduction
-Chapter 1: Model 2 and Struts
-Chapter 2: Input Validation with Action Forms
-Chapter 3: The HTML Tag Library
-Chapter 4: Input Validation and Data Conversion
-Chapter 5: The Validator Plugin
-Chapter 6: The Expression Language
-Chapter 7: JSTL
-Chapter 8: The Bean Tag Library
-Chapter 9: The Logic Tag Library
-Chapter 10: Struts-EL, Nested, selectLabel
-Chapter 11: Message Handling and Internationalization
-Chapter 12: The Tiles Framework
-Chapter 13: Securing Struts Applications
-Chapter 14: The Config Object
-Chapter 15: The Persistence Layer
-Chapter 16: Object Caching
-Chapter 17: File Upload and File Download
-Chapter 18: Paging and Sorting
-Chapter 19: Preventing Double Submits
-Chapter 20: Early HttpSession Invalidation
-Chapter 21: Decorating Request Objects
-Chapter 22: How Struts Works

Previous
Next

 

Overview of the Chapters

This book is for the reader who wants to learn how to develop Struts applications. However, this book does not stop short here. It takes the extra mile to teach how to design effective Struts applications. As the title suggests, this book is designed as a tutorial, to be read from cover to cover, written with clarity and readability in mind.

The following is the overview of the chapters.

Chapter 1, “Model 2 and Struts”, explains the Model 2 architecture and provides two Model 2 applications. It also introduces Struts as a popular framework for rapidly building Model 2 applications.

Chapter 2, “Input Validation with Action Forms”, discusses one of the main features of Struts that helps with user input validation. Input validation is an important task in Web application development which includes checking if there is a value in a mandatory field, whether a date or a number was entered in the correct format, etc. Struts action forms make input validation easy and enable applications to show error messages and redisplay the previous field values without the need to write Java code.

Chapter 3, “The HTML Tag Library”, explains the tags in the HTML Tag Library, one of the three core tag libraries that come with Struts. To make full use of Struts you should always use these tags to generate HTML forms and other HTML elements in your JSPs.

Chapter 4, “Input Validation and Data Conversion”, discusses input validation in detail. In addition, it deals with data conversion, a task that almost always precedes input validation. Three examples are presented and the utility class BeanUtils, from the Jakarta Commons project, is discussed.

Chapter 5, “The Validator Plugin”, discusses one of the most useful features in Struts, the Validator plugin. With this plugin you can validate user input without writing Java code. Chapter 5 presents how to use and extend this plugin in minute detail.

Chapters 6 to 9 explained how to access model objects in the MVC pattern from JSPs. Chapter 6, “The Expression Language”, covers the Expression Language (EL) in JSP 2.0. The EL is one of the most important features in JSP 2.0 that can help you write shorter and more effective JSPs, as well as help you author scriptlet-free pages.

Chapter 7, “JSTL”, covers JSTL’s tags used for accessing scoped objects and scoped objects’ properties, iterating members of a collection, performing conditional tests, parsing and formatting dates and numbers, and functions useable from JSP 2.0 EL expressions.

Chapter 8, “The Bean Tag Library”, covers the Bean Tag Library, one of the Struts’ three core tag libraries, whose tags are mainly used to access scoped objects and various objects in the HttpServletRequest object.

Chapter 9, “The Logic Tag Library”, explains the Logic Tag Library, which contains tags for comparing values, matching strings, forwarding and redirecting users, and iterating collections.

Chapter 10, “Struts-EL, Nested, selectLabel” explains the Struts EL Tag Library, the Nested Library, and a custom tag called selectLabel. The latter is used to display the text of a selected option.

Chapter 11, “Message Handling and Internationalization”, covers message handling, which is also one of the most important tasks in application development. Today it is also often a requirement that applications be able to display internationalized and localized messages. Struts has been designed with internationalization and localization in mind and tags in the core tag libraries all support internationalized message handling. In addition, this chapter shows how you can use several tags in JSTL to support message displaying and formatting.

Chapter 12, “The Tiles Framework” discusses how you can achieve a consistent look in your Struts applications using the Tiles framework. Tiles, which is vastly superior to JSP includes, allows you to write layout and definition pages There are two types of definition pages, JSP and XML, and definition elements or tags inside definition pages can be extended.

In Chapter 13, “Securing Struts Applications”, you will learn how to configure the deployment descriptor to restrict access to some or all of the resources in your applications. What is meant by “configuration” is that you need only modify your deployment descriptor file—no programming is necessary. In addition, you will also learn how to use the roles attribute in the action element in your Struts configuration file. Writing Java code to secure Web applications is also possible through the following methods of the javax.servlet.http.HttpServletRequest interface: getRemoteUser, getPrincipal, getAuthType, and isUserInRole.

Chapter 14, “The Config Object”, teaches how to implement a Config object that stores key/value pairs that are available throughout the application. Key/value pairs may come from the deployment descriptor or a properties file and an application listener can be used to populate the Config object.

Chapter 15, “The Persistence Layer”, addresses the need of a persistence layer to save value objects. The persistence layer hides the complexity of accessing the database from its clients, notably the Struts action objects. The persistence layer can be implemented as entity beans, the Data Access Object (DAO) pattern, by using Hibernate, etc. This chapter shows you in detail how to implement the DAO pattern. There are many variants of this pattern and which one you choose depends on the project specification. The most flexible DAO pattern is preferable because you can extend your application easily should it need to change in the future.

Creating Java objects is relatively more expensive than other operations, and constructing certain objects, such as database connections, is particularly compute intensive. Chapter 16, “Object Caching”, shows how to cache objects efficiently.

Chapter 17, “File Upload and File Download”, discusses two important topics that often do not get enough attention in Web programming books. Struts supports file upload by seamlessly incorporating the Jakarta Commons FileUpload library. The first section of this chapter discusses how to achieve this programming task in Struts. The second section deals with file download and demonstrates how you can send binary streams to the browser.

In Chapter 18, “Paging and Sorting”, you can learn about paging, a technique that displays data in multiple pages. Paging is used when you are working with a large amount of data. For more effective solutions, you need to identify whether your action retrieves a large collection of data or a very large one. For the former, the effective solution will be cache-based paging. For the latter, it is query-based paging. This chapter also introduces the Display Tag Library that by default supports paging and sorting.

Chapter 19, “Preventing Double Submits”, explains how to use Struts’ built-in features to prevent double submits, which could happen by accident or by the user’s not knowing what to do when it is taking a long time to process a form.

Chapter 20, “Early Session Invalidation” presents a technique that can be used to end the lives of HttpSession objects of users who have closed their browsers, effectively freeing precious memory space.

Chapter 21, “Decorating Request Objects”, explains the use of the Decorator design pattern to wrap HttpServletRequest objects. An example that features a trimmer filter is also presented.

Chapter 22, “How Struts Works”, sums up this book by looking into what happens under the hood. In particular, this chapter explains the three most important types in Struts: ActionServlet, RequestProcessor, and ConfigModule. Understanding how Struts works undoubtedly enables you to write more effective applications.

Appendix A, “Struts Configuration”, is a reference of the Struts configuration file.

Previous
Next