Alternatives to Struts

Before we get too far into our discussion of the Struts framework, this section will briefly introduce some alternatives to Struts. Because versions and features may change with each new release, you should conduct your own research. This list of alternatives is by no means exhaustive, but it will provide you with a launching pad. I could have saved this section for the end of the book, but I wanted to familiarize you with some other frameworks so that you can compare them with Struts as you work through this book.

Note that only solutions based on or around the Java platform are listed here. Microsoft also offers a competing technology based on Active Server Pages (ASP). Although the goal of ASP is similar to that of JSP, ASP and ASP+ are not discussed here—they’re better left for a book on JSP and servlets. Furthermore, the Struts framework goes well beyond what is offered by JSP alone, and comparing ASP or other similar technologies to Struts wouldn’t make sense.

Building Your Own Framework

At first, it might seem strange to present building your own framework as an alternative to using Struts. Why would you want to build frameworks from scratch, when they already exist in many different forms? The answer is the same reason that other open source or commercial products are developed. The available selection of products just might not be close enough to your desired framework, and it might be preferable to build it in-house.

The best advice I can give regarding building your own framework is to ask yourself several questions:

  1. Have I taken the time to inspect what’s available and build a prototype using an available framework?

  2. What does my application need that doesn’t exist in one of the available frameworks?

  3. Can I extend an existing framework to suit my needs or find what I need at another source and add it?

  4. Do I know enough about building this type of framework to be able to meet my requirements?

Depending on the honest answers to these questions, you might find that building your own framework isn’t the best decision. A good guideline to which many in the software-development industry subscribe is that if it pertains to your core business, you should build it in-house, but if the software component is not directly related to your core business, it might be wise to get it elsewhere. Play to your team’s strengths and minimize its weaknesses.

Barracuda

The Barracuda presentation framework is a type of Model 2 architecture similar to Struts, but it goes a step further and provides a model event-notification mechanism. Unlike a strictly JSP approach, the Barracuda framework has created a template engine component, which is supposed to allow for more flexibility and extensibility. The framework leverages code-content separation provided by the XMLC approach of creating user interfaces. XMLC is a Java-based compiler that uses either an HTML or XML document and creates Java classes that can recreate the document when executed. The generated Java classes can be used to insert dynamic content into the document at runtime by manipulating Document Object Model (DOM) interfaces. The separation of markup and application logic allows web designers to focus on markup and programmers to focus on coding.

The one downside to using a framework like this one is that it may have a steeper learning curve for developers. The use of XMLC and the fact that Java classes are created from HTML or XML documents may confuse less experienced developers.

Version 1.0 of the Barracuda framework was released recently. You can find more information on the Barracuda presentation framework at http://barracuda.enhydra.org.

Cocoon

Stefano Mazzocchi founded the Cocoon project in January 1999 as an open source project under the ASF. The goal of Cocoon is to help separate the content style, logic, and management functions for XML-based web sites. Cocoon leverages XML, Extensible Stylesheet Language Transformations (XSLT), and Simple API for XML (SAX) technologies to help create, deploy, and maintain XML server applications. Cocoon currently is at Release 2.0. Most types of data sources, including RDBMS, LDAP, and File Systems, are supported. More information on Cocoon can be found at http://xml.apache.org/cocoon/.

Expresso

The Expresso framework from Jcorporate is an application development framework that provides a component framework for developing database-driven web applications. The Expresso framework can be integrated into Struts and adds capabilities for security, object-to-relational mapping, background job handling and scheduling, and many other features. Expresso is more of a companion product to Struts than a competitor. It is currently at Release 4.0. More information on the Expresso framework can be found at http://www.jcorporate.com.

Freemarker, Velocity, and WebMacro

These three products are grouped together because they all represent similar types of template engines.

Freemarker is an open source HTML template engine for Java servlets. With Freemarker, you store the HTML in templates, which eventually get compiled into template objects. These template objects then generate HTML dynamically, using data provided by servlets. Freemarker uses its own template language and claims speeds approaching those of static HTML pages. The software is free and licensed under the GNU Library Public License. It currently is at Release 2.0. You can find more information about Freemarker at http://freemarker.sourceforge.net.

Velocity is another Jakarta project like Struts. It is a Java-based template engine that is similar in many ways to Freemarker, but it is capable of more than just creating dynamic content for web sites. Velocity can generate SQL, PostScript, and XML from templates, for example, and can be used either as a standalone utility for generating source code and reports or as an integrated component of other systems. Velocity also provides template services for the Turbine web application framework. Many other frameworks either support the Velocity scripting syntax or actually depend on it. For more information on Velocity, go to http://jakarta.apache.org/velocity/.

WebMacro is an open source Java servlet framework used by several large web sites. The WebMacro framework uses a lightweight scripting language that allows separation of how a page looks from the page logic. WebMacro can be run in standalone mode or with a servlet container. It currently is at Release 1.0. More information about WebMacro can be found at http://www.webmacro.org.

Maverick

The Maverick MVC framework offers the ability to render views using JSP, the Velocity scripting language, or XSLT. Maverick is an MVC-type architecture, but it actually provides a view template mechanism. One neat feature of Maverick is that it can use reflection on JavaBeans in the presentation layer to create a DOM interface, so no XML generation or parsing is required. This allows for a little less clutter and probably better performance when using XSLT to generate the views. You can find more information on the Maverick framework at http://mav.sourceforge.net.

SiteMesh

SiteMesh is a web page layout and integration system that makes it easier to create web sites that need a consistent look and feel. SiteMesh intercepts requests to any web page, whether it’s static or dynamically generated, parses the content, and generates a final page. This process is based on the well-known Decorator pattern. [4]

SiteMesh is built with Servlet, JSP, and XML technologies, which makes it appropriate for J2EE applications. However, it also claims to be easy to integrate with other web technologies, such as CGI. More information on SiteMesh can be found at http://www.opensymphony.com/sitemesh/.

Jakarta Turbine

Turbine is a servlet-based framework and an open source Jakarta project. Currently, there isn’t a great deal of documentation for Turbine, but it seems to be similar to Struts, with a few major differences. For one thing, it doesn’t seem to be coupled to JSP. The focus of Turbine appears to be to provide a collection of reusable components. A large set of components is included with the framework, but they are quite disparate. It seems to present more of a component library, but as it’s lacking documentation, it’s hard to get a good feel for the complete architecture. More information on Turbine can be found at http://jakarta.apache.org/turbine/.

WebWork

WebWork is a small web application framework that uses the Pull Hierarchical Model View Controller (HMVC) design. With a standard MVC design, changes made to the model are pushed to the view. In the case of WebWork, the views pull the data when they need it. Interestingly, WebWork doesn’t seem to be tied to a servlet; therefore, it can support other types of clients such as Swing. More information on the WebWork framework can be found at http://sourceforge.net/projects/webwork/.

JavaServer Faces

At the time of this writing, there is a Java Specification Request (JSR) to create a new Java technology called JavaServer Faces . The specification defines the architecture and a set of APIs for the creation and maintenance of Java server web applications. The idea is to create a standard set of JSP tags and Java classes to help developers create complex HTML forms and other graphical user interface (GUI) components based on the Servlet and JSP technologies. I18N and input validation seem to be big parts of the intended support.

JavaServer Faces will be a specification defining a set of standard APIs, not an actual implementation. Vendors will be able to create their own implementations, so developers will have more than one implementation to choose from.

The JSR indicates that the creators of JavaServer Faces are aware that other projects, such as Struts, already have addressed many of the problems that this specification attempts to solve. The JSR is aimed at creating a standard that will help unify this fragmented area. Keep your eye on this specification, as it may have a huge impact on Struts and the entire web application area as a whole.

Recently, Craig McClanahan has been appointed as specification lead for JavaServer Faces. This surely will help ensure a smooth transition for the Struts framework. More information on the specification can be found at http://www.jcp.org/jsr/detail/127.jsp.



[4] The Decorator pattern is a structural design pattern mentioned in the book Design Patterns (Addison Wesley), by Gamma, Helm, Johnson, and Vlissides, affectionately known as the “gang of four.”

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

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.