ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

What Is Struts

by Chuck Cavaness, author of Programming Jakarta Struts, 2nd Edition
Apache Struts is an open source Java framework used for building web applications based on the servlet and JavaServer Pages (JSP) technologies. It was created in 2000 by Craig R. McClanahan and has become the de facto standard framework for web applications in Java.

In This Article:

  1. The Web Development Landscape: Six Years Ago
  2. Along Comes Jakarta Struts
  3. Benefits of the Struts Framework
  4. Overview of the Struts Framework
  5. Choosing a Model Layer for Struts
  6. The Struts Presentation Layer
  7. Struts' Other Great Features
  8. More Information on Struts

Is it conceivable that anyone in the business of building software hasn't heard of the Struts framework? From developers that are just starting out in the business to those long in the tooth, the name "Struts" surely must ring a bell. But if you haven't spent your development time in the Java world or haven't had the need to build web applications, Struts might only be a buzzword that you've added to your resume. For the next five to ten minutes, you're going to be taken on a whirlwind tour of the Struts framework. Get a drink (non-alcoholic, of course), sit back, and put your feet up, and learn a little about one of the most popular free frameworks to ever grace the open source community.

The Web Development Landscape: Six Years Ago

This is going to sound like a grandfather preaching to his grandkids about how tough it was in his day, but prior to 2000, the landscape for developing Java web applications was much different. Java servlets had been out for just a short time (relatively speaking) and Sun had recently released JavaServer Pages (JSP) to counter Microsoft's Active Server Pages (ASP) technology. JSPs caught on like wildfire and before long, many web applications were being built using JSPs.

Unfortunately, in an effort to get applications quickly out the door and due to a lack of any best practices in the industry at the time, many JSP applications became a tangled web of pages as developers crammed as much of the application functionality into the JSP. This approach to building JSP applications would eventually be called the JSP "Model 1" architecture and is shown in Figure 1.

Figure 1
Figure 1. The JSP Model 1 architecture

The Model 1 architecture used the JSPs to handle the HTTP requests, communicate with the data layer (via JavaBeans), and to render the next page back to the client. For small applications, this approach isn't so terrible. But for non-trivial applications where there are many pages or when the functionality is more traditionally application-like, the Model 1 architecture presents many maintenance and upgradeability challenges.

Developers soon realized that the use of JSPs in conjunction with a single controller servlet could improve this design greatly. The separation of the presentation layer from the business logic not only serves to keep the JSPs cleaner, but it allows development teams to utilize each team member's specialized skill.

This new approach to building JSP applications became known as the JSP "Model 2" architecture. It was patterned after the Model-View-Controller (MVC) design, which originated from Smalltalk, where it was used to separate the GUI from the business layer. (When MVC is done on the Web, it is often referred as Web MVC.) The JSP Model 2 architecture is shown in Figure 2.

Figure 2
Figure 2. The JSP Model 2 architecture

The Model 2 architecture uses a Java servlet to receive the HTTP requests from the browser and to communicate with the model layer. The JSPs are used only for presentation. The same controller that receives the request is responsible for determining which view gets returned back to the client.

Pages: 1, 2, 3, 4, 5

Next Pagearrow