Chapter 3: The Model Layer


Understanding the Flow of Execution

Before leaving the Mini HR example, it is necessary to describe the way that execution takes place. As explained in Chapter 1, Struts uses the Model-View-Controller design pattern. The MVC architecture defines a specific flow of execution. An understanding of this flow of execution is crucial to an overall understanding of Struts.

For Mini HR, execution proceeds in the following way:

  1. The browser makes a request to Mini HR for an employee lookup. This request is processed by ActionServlet (Controller).

  2. ActionServlet populates the SearchForm object (View) with the search criteria entered on the search.jsp page.

  3. ActionServlet delegates request-specific processing to the SearchAction object (Controller).

  4. SearchAction (Controller) interfaces with the EmployeeSearchService object (Model) to perform the employee search. EmployeeSearchService returns an ArrayList of Employee objects (Model).

  5. SearchAction (Controller) forwards control to search.jsp (View).

  6. search.jsp (View) uses the ArrayList of Employee objects (Model) to generate a response to the browser.

The flow of execution for Mini HR can be generalized for any Struts application as shown here. Figure 2-6 shows the flow execution in graphic form.

  1. The browser makes a request to the Struts application that is processed by ActionServlet (Controller).

  2. ActionServlet (Controller) populates the ActionForm (View) object with HTML form data and invokes its validate( ) method.

  3. ActionServlet (Controller) executes the Action object (Controller).

  4. Action (Controller) interfaces with model components and prepares data for view.

  5. Action (Controller) forwards control to the JSP (View).

  6. JSP (View) uses model data to generate a response to the browser.

image from book
Figure 2-6: Flow of execution

Remember, the same basic pattern of execution applies to any Struts application.

Now that you understand the basic structure of a Struts application and how its components work together, it's time to move on to an in-depth examination of Struts. As mentioned at the start, all of the topics presented in this chapter are examined in detail in the chapters that follow.



Struts. The Complete Reference
Struts: The Complete Reference, 2nd Edition
ISBN: 0072263865
EAN: 2147483647
Year: 2004
Pages: 165
Authors: James Holmes

Similar book on Amazon
Struts 2 in Action
Struts 2 in Action
Murach's Java Servlets and JSP, 2nd Edition
Murach's Java Servlets and JSP, 2nd Edition
Jakarta Struts For Dummies
Jakarta Struts For Dummies
Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam
Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam

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