My developer connection home My Developer Connection
knowledgebase for software developers

What is Struts?

  • An open source Jakarta Apache project
  • An Implementation of a MVC Paradigm
  • A framework written in Java
  • A web-tier layer built on Servlets, JSP, and XML.

An open source Jakarta Apache project
Struts is part of the Apache Jakarta Project, sponsored by the Apache Software Foundation.  http://jakarta.apache.org/struts/index.html

Struts is an implementation of the Model-View-Controller (MVC) pattern: This is considered a Model 2 architecture. (Model 1 architecture combines the roles of the view and controller components.)
The model component handles the business domain state and data
The view component handles the presentation of the business domain.
The controller component processes the user input to direct the flow and manage user state.

Model View Controller Components:
A framework written in Java
Some of the classes in the frame work are:
    ActionServlet
    RequestProcessor
    ActionMapping
    Action
    ActionForm
    ActionForward


ActionServlet:
The Struts ActionServlet class extends the javax.servlet.http.HttpServlet class and is responsible for packaging and routing HTTP traffic to the appropriate handler.
This servlet takes on administering the behavior of the �Controller�.
The ActionServlet is configured via the deployment descriptor of the web application and is typically is configured in the deployment descriptor to accept a pattern of URLs such as *.do.

RequestProcessor:
Takes on the behavior of the �Controller� by handling the core processing logic.
Determine the ActionMapping associated with the request and instantiates the Action.
Instantiates ActionForm if needed.
Processes the ActionForward.

ActionMapping:
Maps a path attribute to that of an incoming URI
 

Action:
The RequestProcessor delegate the work to be done to an Action.
Provides loose coupling between the user request and the business layer.
public ActionForward execute(ActionMapping mapping,
ActionForm form,
ServletRequest request,
ServletResponse response)
throws IOException, ServletException

ActionForm:
Hold state and behavior for user input.
Can be used to validate presentation data.
Should be used to encapsulate data that is for delivery to the data model.

ActionForward:
Encapsulates the destination of where to send control upon completion of the Action.
The destination is detailed in the configuration file: HTML, JSP, servlets.
 

Configuring Struts:
There are two configuration files: web.xml and struts-config.xml
The deployment descriptor for servelets is the web.xml file.
Struts specific information resides in the struts-config.xml file.
web.xml Deployment Descriptor route request to the ActionServlet.
struts-config.xml: The primary Struts framework configuration and implementation configuration are contained in the stuts-config.xml file.
The power and flexibility of Struts is due to the extracting of configuration information from across the frame work. struts-config.xml may be given a different name.

Features:

Built in exception handling at an action an global scope are specified in the config file.
I18 N, Internationalization, support with resource bundles.

JSP custom tags:
Validator framework from the jakarta.commons project; this is set up as a plugin and configured via validation.xml and validation-rules.xml
Tiles � a templating mechanism incorporated into Struts for managing page layout.
Supports database access classes.

Best Practices:
The Action should not perform any business logic. (Action is part of the controller).
The ActionForm should not be used as the data model.
The ActionForm should not be used to validate business objects.