Preface

The road to successful web applications is paved with the sweat and heartache of the many who came before us. The idea of taking a rich client application and allowing it to execute over the Internet was a great leap of faith, and maybe just a little shortsighted. By “web applications,” I don’t mean small, trivial applications that accept a form or two of input and push it into a database; I mean large applications that cross several tiers, use many different technologies, and cover the spectrum of analysis and design-pattern uses.

The design and construction of these types of applications push developers to the limit of what’s logically and physically possible. Myriad solutions have been thrown at the problems these applications present. Some of the solutions stuck, and some did not—and when a solution didn’t serve the needs of the users, it was obvious. But as with human evolution, the valuable characteristics eventually were passed on, and the characteristics that failed to serve their intended purposes fell by the wayside.

The user interface (UI) in Smalltalk-80™ was designed around the Model-View-Controller (MVC) framework. Over time, this framework has been adopted as a classic design pattern and used in many different scenarios. Other UI frameworks, such as the one written for Java™ Swing, use similar concepts. The architects of the JavaServer Pages™ (JSP) specification formally introduced the abstract idea of two types of models for web-based solutions: Model 1 and Model 2. The distinguishing feature between the two is that Model 2 uses a separate component to handle the controller responsibilities. This allows JSP to focus exclusively on rendering the view while using JavaBeans™ as the model, thereby effectively becoming an abstract implementation of a web-based MVC architecture.

The Struts framework, created by Craig R. McClanahan and donated to the Apache Software Foundation (ASF) in 2000, is an open source implementation of Model 2 ideas. This book covers Version 1.1 of the Struts framework, but because backward compatibility was one of the design goals of 1.1, 1.0 Struts developers also will find value in reading this book.

If you learn one thing from this book, it should be that frameworks such as Struts are a great time investment. If you are building applications, web-based or not, you should be using at least one framework, and as web frameworks go, Struts is one of the best.

Organization

This book begins with a preliminary discussion that lays the groundwork for the rest of the material. This discussion will be a refresher for some and completely new for others. From there, we explore the components of Struts’s MVC implementation, including a look at the JSP custom tags that are included as part of the framework. Then, to round out your understanding of the value of the Struts framework, we look at several complicated but important topics related to building web-based applications.

Chapter 1

This chapter discusses some preliminary concepts, such as the MVC pattern, Model 2, and the idea of a software framework. Although many developers may already be familiar with some or all of the ideas presented here, I wanted to ensure that all readers are starting from the same place. The concepts presented in this chapter help to lay the foundation for the rest of the book.

Chapter 2

The Struts framework is based on the Java Servlet technology and, to a lesser extent, JavaServer Pages, and therefore is tightly coupled to a web container. For Struts developers, understanding how the web container processes client requests is fundamental to understanding the framework itself. This chapter discusses the components of the web container and the responsibilities of each.

Chapter 3

This chapter provides an overview of the Struts framework; it does not attempt to cover all of the features or go into significant depth. It emphasizes how all the pieces fit into the MVC and Model 2 architecture presented in Chapter 1.

Chapter 4

The Struts framework uses two separate but somewhat related types of configuration files, which must be configured properly before an application will function properly. Due to the popularity and flexibility of XML, both types of configuration files are based on XML. This chapter presents the syntax of the files.

Chapter 5

The Struts framework uses a servlet to process incoming requests; however, it relies on many other components that are part of the controller domain to help it carry out its responsibilities. This chapter takes in-depth look at the components that are responsible for the controller functionality in the framework.

Chapter 6

This chapter introduces the components that make up the model portion of a Struts application. The model represents the business data for an application and should closely resemble the real-world entities and business processes for the organization. This chapter explores the roles and responsibilities of the model components within the Struts framework and focuses on building an architecturally correct implementation for the Storefront application. Special attention is given to using a persistence framework that can be integrated into a Struts application easily and effortlessly.

Chapter 7

Chapter 7 introduces the components that make up the view portion of the Struts framework. The framework uses the view components to render dynamic content for the client. Based primarily on JavaServer Pages, the components provide support for internationalized applications as well as for user-input acceptance, validation, and error handling, all of which make it easier for the developer to focus on business requirements. This chapter concludes the three-part discussion of how the Struts framework implements the MVC pattern.

Chapter 8

This chapter looks at the different categories of tags and how they can help make developing applications with the Struts framework even easier. It is not meant to be an exhaustive reference for every tag that’s part of the Struts tag libraries—that information can be found within the Struts user guide or JavaDocs. The real purpose of this chapter is to put forth the benefits of using the Struts tag libraries and to provide a few strategies that can help make the switch to using the tags less painful.

Chapter 9

One of the biggest advantages of using a framework is the ability to extend and customize it based on the needs of the application. The Struts framework is no exception; it provides several important extension points for developers. This chapter takes a quick glance at several of those extension points and examines the benefits and drawbacks of extending the framework.

Chapter 10

This chapter looks at how to use the Java exception-handling mechanism within your Struts applications to make them more robust and allow them to respond gracefully when things don’t go as expected. Special attention is given to the differences between performing the exception handling programmatically and using the new declarative feature added to the Struts framework in Version 1.1.

Chapter 11

This chapter introduces the Validator framework, which was created specifically to work with Struts components. The Validator allows you to declaratively configure validation routines for a Struts application without having to program special validation logic.

Chapter 12

This chapter focuses on what it takes to make a Struts application available to customers from around the world, regardless of their language or geographical location. As is often the case in software development, planning ahead is the most important thing that you can do to help ensure success. After reading this chapter, you should be able to build Struts applications that can support a broad range of customers.

Chapter 13

Chapter 13 covers the issues you need to consider when developing an interface between your Struts actions and an application tier. It focuses on interfacing to a model built using Enterprise JavaBeans™ (EJB).

Chapter 14

This chapter looks at the Tiles framework, which now is part of the core Struts distribution. The Tiles framework is an advanced templating framework that reduces the amount of redundant code a web application contains and allows developers to better separate content from layout.

Chapter 15

This chapter examines how the use of logging in your Struts applications can help you identify defects before the applications get into production and, if your software already is being used in production, how logging can help you identify problems and arrive at solutions much more quickly.

Chapter 16

This chapter discusses the best practices for packaging and deploying a Struts application and what it takes to automate the build process for your environment. Special coverage is given to Ant, the Java-based build tool available from Jakarta.

Chapter 17

This chapter explores the performance implications of using the Struts framework and its associated technologies to build web applications and discusses how certain design and programming decisions affect the overall performance of the applications. It covers performance, load, and stress testing, and the steps necessary to carry out each.

Appendix A

This appendix enumerates the new features within the 1.1 release.

Appendix B

This appendix discusses the steps for downloading and installing Struts in your environment.

Appendix C

This appendix lists several resources that can help increase your knowledge once you’ve mastered the concepts in this book.

Get Programming Jakarta Struts now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.