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

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

问题描述

在Struts2中,控制器将请求分发给操作,然后该操作将其传递到后端逻辑(可以认为是一个非常大的模型")以处理请求,而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?绝对不是View ...是Controller还是Model?

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

推荐答案

在MVC模式的意义上,Struts动作是控制器.动作类中的getter方法也使这个问题感到困惑.通常,这些只是其他对象(通常是Model对象)的容器.

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框架时,您会发现这些框架通常同时提供Controller和View组件,但这是您自己构建Model的工作.即使这样,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中使用的动作是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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