就MVC模式而言,Struts 2中使用的Action是什么? [英] What is Action used in Struts 2 in terms of MVC pattern?

查看:22
本文介绍了就MVC模式而言,Struts 2中使用的Action是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Struts2 中,控制器向 Action 分派请求,Action 将请求传递给后端逻辑,后端逻辑可以看作是一个非常大的模型来处理请求,JSP 代表视图.

In Struts2, a controller dispatches a request to an Action and the Action passes it to back-end logic, which could be regarded as a very big model, to process the request and JSP represents Views.

如何在Struts2中定义Action?绝对它不是一个视图.是控制器还是模型?

How to define the Action in Struts2? Definitely it's not a View. Is it the Controller or Model?

推荐答案

Struts 动作是 MVC 模式意义上的控制器. 我认为关于值堆栈和 ActionContext 以及操作类中的 getter 方法混淆了这个问题.一般来说,这些只是其他对象(通常是模型对象)的容器.

Struts actions are controllers in the sense of the MVC pattern. I think the discussion of the value stack and ActionContext, as well as getter methods in action classes confuses the issue. In general, these are simply containers for other objects (usually Model objects).

虽然@AndreaLigios 指出您可以使用各种 get 方法从动作中检索对象,但这更多的是通过赋予通常分配给模型对象的额外职责来稀释动作内聚力的问题.是的,当您考虑要做什么(或应该做什么)时,评估对象的职责很重要.

While @AndreaLigios points out that you can retrieve objects from the action using various get methods, that's more an issue of diluting the actions cohesion by giving it additional responsibilities normally assigned to model object. Yes, it's important to evaluate the responsibilities of your objects when you're considering what the do (or should be doing).

简单来说,所有MVC框架中主要组件的职责如下:

Put most simply, the responsibilities of the major components in all MVC framework are as follows:

  • 模型对象负责保存在您的应用程序域中收集或计算的数据.
  • 视图对象负责向用户或其他接收者(如服务客户端)显示信息
  • 控制器对象负责协调模型和视图组件之间的数据流.

当您查看像 Struts(或 Spring MVC)这样的特定 MVC 框架时,您会发现这些框架通常同时提供控制器和视图组件,但您自己构建模型是您的工作.即便如此,Struts 还是提供了丰富的附加对象和组件,例如 ActionContext,使从 View 组件访问模型对象变得更加容易.

When you look at a specific MVC framework like Struts (or Spring MVC) you'll see that the frameworks usually provide both Controller and View components, but it's your job to build out the Model yourself. Even so, Struts provides a wealth of additional objects and components, like ActionContext, that make it easier to access your Model objects from your View components.

这篇关于就MVC模式而言,Struts 2中使用的Action是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆