Struts 2 简明教程
Struts 2 - Architecture
从高层次来说,Struts2 是一个 pull-MVC(或 MVC2)框架。Struts2 中的模型-视图-控制器模式使用以下五个核心组件实现 -
From a high level, Struts2 is a pull-MVC (or MVC2) framework. The Model-ViewController pattern in Struts2 is implemented with the following five core components −
-
Actions
-
Interceptors
-
Value Stack / OGNL
-
Results / Result types
-
View technologies
Struts 2 与传统的 MVC 框架略有不同,其中操作充当模型而不是控制器,尽管有一些重叠。
Struts 2 is slightly different from a traditional MVC framework, where the action takes the role of the model rather than the controller, although there is some overlap.
上图描述了 M*odel, *V*iew and *C*ontroller to the Struts2 high level architecture. The controller is implemented with a *Struts2 调度 servlet 过滤器以及拦截器,此模型使用操作实现,而视图是结果类型和结果的组合。值堆栈和 OGNL 提供公共线程,链接和启用其他组件之间的集成。
The above diagram depicts the M*odel, *V*iew and *C*ontroller to the Struts2 high level architecture. The controller is implemented with a *Struts2 dispatch servlet filter as well as interceptors, this model is implemented with actions, and the view is a combination of result types and results. The value stack and OGNL provides common thread, linking and enabling integration between the other components.
除了上述组件外,还将存在大量与配置相关的信息。Web 应用程序配置,以及动作、拦截器、结果等配置。
Apart from the above components, there will be a lot of information that relates to configuration. Configuration for the web application, as well as configuration for actions, interceptors, results, etc.
这是 Struts 2 MVC 模式的架构概览。我们将在后续章节中更详细地介绍每个组件。
This is the architectural overview of the Struts 2 MVC pattern. We will go through each component in more detail in the subsequent chapters.
Request Life Cycle
根据上图,您可以理解用户请求生命周期中的工作流程 Struts 2 如下 −
Based on the above diagram, you can understand the work flow through user’s request life cycle in Struts 2 as follows −
-
User sends a request to the server for requesting for some resource (i.e. pages).
-
The Filter Dispatcher looks at the request and then determines the appropriate Action.
-
Configured interceptor functionalities applies such as validation, file upload etc.
-
Selected action is performed based on the requested operation.
-
Again, configured interceptors are applied to do any post-processing if required.
-
Finally, the result is prepared by the view and returns the result to the user.