Struts 2 简明教程

Basic MVC Architecture

M*odel *V*iew *C*ontroller or *MVC (这是人们通常叫法),是一种用于开发 Web 应用程序的软件设计模式。Model View Controller 模式由以下三部分构成−

M*odel *V*iew *C*ontroller or *MVC as it is popularly called, is a software design pattern for developing web applications. A Model View Controller pattern is made up of the following three parts −

  1. Model − The lowest level of the pattern which is responsible for maintaining data.

  2. View − This is responsible for displaying all or a portion of the data to the user.

  3. Controller − Software Code that controls the interactions between the Model and View.

MVC 很受欢迎,因为它将应用程序逻辑从用户界面层隔离出来,并支持关注点分离。在这里,控制器接收所有应用程序请求,然后与模型协作准备视图所需的所有数据。随后,视图使用控制器准备的数据生成最终的可展示响应。MVC 抽象可图形化表示如下。

MVC is popular as it isolates the application logic from the user interface layer and supports separation of concerns. Here the Controller receives all requests for the application and then works with the Model to prepare any data needed by the View. The View then uses the data prepared by the Controller to generate a final presentable response. The MVC abstraction can be graphically represented as follows.

struts mvc

The Model

模型负责管理应用程序的数据。它响应视图的请求,并且还响应控制器的指令来更新自身。

The model is responsible for managing the data of the application. It responds to the request from the view and it also responds to instructions from the controller to update itself.

The View

这意味着通过控制器的决策来呈现特定格式的数据的展示。它们是基于脚本的模版系统,如 JSP、ASP、PHP,非常容易与 AJAX 技术集成。

It means presentation of data in a particular format, triggered by a controller’s decision to present the data. They are script-based templating systems like JSP, ASP, PHP and very easy to integrate with AJAX technology.

The Controller

控制器负责响应用户输入,并在数据模型对象上执行交互。控制器接收输入,验证输入,然后执行修改数据模型状态的业务操作。

The controller is responsible for responding to the user input and perform interactions on the data model objects. The controller receives the input, it validates the input and then performs the business operation that modifies the state of the data model.

Struts2 是一个基于 MVC 的框架。在接下来的章节中,我们将看到如何在 Struts2 中使用 MVC 方法。

Struts2 is a MVC based framework. In the coming chapters, let us see how we can use the MVC methodology within Struts2.