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.
本文介绍了Struts框架的工作原理。Struts采用Model 2架构,ActionServlet控制导航流,Action用于访问业务类。它能验证输入、访问数据库。输入被打包成JavaBean,由ActionForm处理。请求完成业务逻辑后,通过ActionForward转发到其他资源。相关配置在struts - config.xml文件中。
106

被折叠的 条评论
为什么被折叠?



