Struts uses a Model 2 architecture

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值