CHAPTER 4: Building a Web Application Using Struts 2 163
The sequence of events in Struts is as follows:
- The ActionServlet delegates request processing to a RequestProcessor.
- The RequestProcessor processes the request and stores the form values in
the ActionForm. - The RequestProcessor then invokes the Action class.
- The Action class accesses the ActionForm to retrieve the form values.
- The Action class invokes the call to the service layer.
- The Action class returns the ActionForward, which is used to encapsulate
the response view.
Struts 2, however, is different from Struts. Unlike Struts, which follows a push-MVC architecture
where data is expected to be present in the page or scope, Struts 2is a pull-MVC architecture; that
is, the data can be pulled from the Action. Table 4-2 shows a one-to-one mapping of the Struts and
Struts 2 framework elements.
Table 4-2. One-to-One Mapping of Struts and Struts 2Framework Elements
Struts Framework Elements Struts 2 Framework Elements
ActionServlet Servlet filter
RequestProcessor Interceptor
Action Action
ActionForm Action or POJOs
ActionForward Result
Note You can find a comprehensive list of similarities and differences between Struts and Struts 2 at
http://struts.apache.org/release/2.3.x/docs/comparing-struts-1-and-2.html.
Figure 4-2 illustrates the key elements of Struts 2 that provide a cleaner implementation of MVC.