Exploring the Struts Architecture

Struts represents an implementation of MVC type 2 architecture. The most important components of Struts are the ActionServlet, Action, and ActionForm subclasses. ActionServlet represents the controller that intercepts the requests and forwards them for further processing based on the configuration file for the ActionForm and Action subclasses. ActionForm transfers data users entered to Action, which performs necessary operations using the Business Tier components of the application and finally forwards to a view. An overview of the Struts MVC architecture appears in Figure 19-1.

image from book
Figure 19-1: Struts MVC architecture

The controller (ActionServlet) uses a configuration file (typically struts-config.xml) to load definitions of the Action subclasses that will be used to handle the requests. Based on the request URL, the controller finds an action definition that is going to handle the request. The Struts framework processes the request, checks the configuration files, and performs the following actions:

  • If the action requires a form bean, the controller creates an appropriate instance of it. The form bean is used to collect data from the user; it usually exposes properties for the data to be collected. It can also validate the data by overriding the validate() method.

  • The action instance is created and its execute() method is called. The primary purpose of the action bean is to perform any logic necessary to process the request. Once the action bean finishes processing the request, it returns an ActionForward instance to indicate to the controller the action that needs to be performed next. The ActionForward instance can represent a forward to another action or a view that displays the model represented by the form bean and any attributes set in the request and session scopes.

The architecture of Struts offers much more than we covered in this short introduction. In this chapter, we continue to use Struts plugins to demonstrate details of Spring integration and the use of other view technologies.



Pro Spring
Pro Spring
ISBN: 1590594614
EAN: 2147483647
Year: 2006
Pages: 189

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net