JBoss Tools 3 Developers Guide
上QQ阅读APP看书,第一时间看更新

Overview of Struts

Struts is one of the most popular open source frameworks for developing web applications based on Java programming language. Developed by Apache, under Jakarta project, Struts encourage the MVC (Model-View-Controller) design paradigm and it is based on standard technologies such as Java Beans, Java Servlets, Resource Bundle, XML, and so on. Using a few bullets, we can resume the Struts implementation of MVC as follows:

  • There is a servlet controller that manages the flow between JSP pages
  • There are a set of special classes dealing with data access
  • Action forwards and action mappings translate the decisional flow control out of the presentation layer
  • JSP pages can refer to logical destinations
  • Controller component provides actual URIs at runtime
  • Special tag library for JSP pages can be used to employ the framework in a productive way

Basically, Struts is made up of a set of components that interact with each other to sustain the MVC architecture. From the Struts components, we mention the following:

Model (M) components:

  • ActionForm beans
    • Each application input form has an ActionForm bean
    • It defines a property for each form's field and the corresponding getXXX and setXXX methods
    • It places the bean instance on form and uses the nested property references

View (V) components:

  • Tag libraries
    • JSP tag extension for HTML forms (struts-html.tld)
    • JSP tag extension for Java Beans (struts-bean.tld)
    • JSP tag extension for testing the values of properties (struts-logic.tld)
  • Input field types
    • Checkboxes, radio buttons, text input fields, select lists, options, hidden fields, and so on
  • Presentation tags
    • <iterate>—repeat its tag body for each element of a Collection. This is a logic tag
    • <present>—checks the current request for a particular attribute, and evaluates its body only if the tested attribute is present. This is a logic tag.
    • <notPresent>—opposite of <present> tag. This is a logic tag.
    • <parameter>—Retrieves the value of the specified parameter and defines the result as a page scope attribute. This is a bean tag.
    • <img>—dynamically generates an HTML <img> element. This is an HTML tag.
    • <link>—dynamically generates an HTML <a> element. This is an HTML tag.

Controller (C) components:

  • ActionServlet class
    • This is the controller servlet responsible for mapping requests URIs to Action classes.
  • Action class
    • An extension of Action class that deals with a logical request
  • struts-config.xml
    • The Struts main configuration file. Among many other things, it contains the action mapping used to configure the controller servlet.
  • validation.xml
    • Contains entries directly related to data validation issues
  • web.xml
    • Contains the necessary Struts components

Note that these are the theoretical aspects of the Struts framework meant to get you familiar with the model and components of the Struts engine. For practical examples and a complete tutorial, you can access resources such as http://www.roseindia.net/struts/ or http://www.strutstutorial.com/. If you never worked with Struts, or you have minimum experience, then it is absolutely mandatory to access a more detailed documentation before going further.