Struts uses a Model 2 architecture

来源:互联网 发布:java聊天程序源代码 编辑:程序博客网 时间:2024/04/20 01:29

Struts uses a Model 2 architecture. The Struts ActionServlet controls the navigational
flow. Another Struts class, the Action, is used to access the business classes.
When the ActionServlet receives a request from the container, it uses the URI (or
path”) to determine which Action it will use to handle the request. An Action can
validate input and access the business layer to retrieve information from databases
and other data services.
To validate input or use the input to update a database, the Action needs to
know what values were submitted. Rather than force each Action to pull these
values out of the request, the ActionServlet bundles the input into a JavaBean.
The input beans are subclasses of the Struts ActionForm class. The ActionServlet
can determine which ActionForm to use by looking at the path of the request, in

the same way the Action was selected. An ActionForm extends org.apache.
struts.action.ActionForm.
Each HTTP request must be answered with an HTTP response. Usually, a Struts
Action does not render the response itself but forwards the request on to another
resource, such as a JSP page. Struts provides an ActionForward class that can be
used to store the path to a page under a logical name
. When it has completed the
business logic, the Action selects and returns an ActionForward to the servlet. The
servlet then uses the path stored in the ActionForward object to call the page and
complete the response.
Struts bundles these details together into an ActionMapping object. Each
ActionMapping is related to a specific path. When that path is requested, the servlet
retrieves the ActionMapping object. The mapping tells the servlet which
Actions, ActionForms, and ActionForwards to use.
All of these details, the Actions, ActionForms, ActionForwards, ActionMappings,
and some other things, are declared in the struts-config.xml file. The Action-
Servlet reads this file at startup and creates a database of configuration objects. At
runtime, Struts refers to the objects created with the configuration file, not the
file itself. Figure 1.1 illustrates how these components fit together.
Believe it or not, you already know enough about Struts to assemble a simple
application. It won’t do much, but it will illustrate how Struts actually works.

原创粉丝点击