This page gives overview of the features of the Jakarta Struts framework.

MVC Components 1.Model • Application data 2.View • Translates Model into readable form 3.Controller • Processes user input • Initiates change in state of Model • In web design also responsible for flow control

--Dickinson


Introduction#

Struts is a web application framework for developing servlet/JSP based applications. It concentrates on the web tier and, aside from providing a simple JDBC connection pool, does not attempt to address persistence requirements.

It does, however, suggest and encourage the use of a domain object model and business logic beans. To this end, its tag libraries include a number of tags for working with JavaBeans.

Request dispatching#

Struts provides a single controller servlet that dispatches requests to Action objects according to the configuration defined in the struts-config.xml file.

Form processing#

HTML forms are defined in JSPs using the Struts <html:form> tag and a comprehensive set of sub-tags, mirroring the regular HTML form tags.

An ActionForm subclass can be written as a JavaBean to encapsulate the form data. The ActionForm should provide a getter and setter for each form field, named after the field's property name.

On submission of a form, each form field value is copied to the corresponding attribute of the ActionForm bean.

When composing the response, each form field is initialised with the value of the corresponding attribute from the ActionForm bean.

ActionForm subclasses can optionally implement a validate() method to perform simple validation (check for mandatory fields, etc.) on the form data before control is transferred to the Action object. If any validation errors are returned by this method, request processing stops and the response is generated using the input page. Error messages can be included in the response using the Struts <html:errors> tag.

Request handling#

Action objects are subclasses of the Struts Action class and should override the perform() method to handle the request.

If the Action is configured to use an HTML form, the populated ActionForm is passed to this method.

Action objects would normally delegate processing to business logic beans and can add errors to the request for output by the <html:errors> tag in a similar manner to the ActionForm.

Action object are also responsible for determining the page to be output following processing of the request. They do this by returning an ActionForward object from their perform() method. The ActionForward object is created by specifying a symbolic name that is mapped to a JSP in the struts-config.xml file. The symbolic name may be local to the action, or global to the application.

Output composition#

Struts uses JSPs to compose the response and provides several tag libraries to assist in the process.

Tag libraries#

In addition to the html tag library discussed above, Struts also includes logic and bean tag libraries.

logic taglib#

The logic tag library provides a number of tags for conditional processing (testing for equality, less than, greater than, etc.) and for iterating over a collection.

bean taglib#

The bean tag library provides tags for creating new beans based on other elements and outputing bean properties to the response.

Templates#

Struts also supports the use of template-based JSPs. A template JSP can be created to define a standard layout for a page. Placeholders can be inserted in the template using the <template:get> tag from the Struts template tag library. JSPs can then be written based on the template using the <template:insert> tag to specify the template name and the <template:put> tag to supply values for the placeholders in the template.

Tiles
Struts works very well with Tiles making template building easy.
--JeremyWhiting

Internationalisation#

Struts supports i18n using standard Java resource bundles. Values from a resource bundle can be output to a page using the <bean:message> tag which takes the name of a resource bundle key as an attribute.

Resource bundle keys are also used when creating errors for the <html:errors> tag to support internationalised messages.

Further reading#

For further details, see the Struts Home Page

To learn more about struts take a look at StrutsHowto.

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-18) was last changed on 14-Sep-2004 08:02 by 203.145.184.117