简体   繁体   English

Struts2中的getContextMap()和getValueStack()之间的区别?

[英]Difference between getContextMap() and getValueStack() in Struts2?

Please tell what is the diffference between: 请说出两者之间的区别是什么:

ValueStack stack=ActionContext.getContext().getValueStack();

and: 和:

Map cont = ActionContext.getContext().getContextMap();

Value Stack (Taken from struts mailing list) 值堆栈(取自struts邮件列表)

A value stack is essentially a List. 值堆栈本质上是一个列表。 Calling [1] on the stack, returns a substack beginning with the element at index 1. It's only when you call methods on the stack that your actual objects will be called. 在堆栈上调用[1],将返回以索引1的元素开头的子堆栈。只有在调用堆栈上的方法时,才会调用实际对象。

Said another way, let's say I have a value stack that consists of a model and an action as follows: 换句话说,假设我有一个由模型和操作组成的值堆栈,如下所示:

[ model, action ] [模型,动作]

here's how the following ognl would resolve: 以下ognl的解决方法如下:

[0] - a CompoundRoot object that contains our stack, [model, action] [0]-包含我们的堆栈的CompoundRoot对象,[模型,操作]

[1] - another CompoundRoot that contains only [action] [1]-另一个仅包含[action]的CompoundRoot

[0].toString() - calls toString() on the first object in the value stack (excluding the CompoundRoot) that supports the toString() method [0] .toString()-在支持toString()方法的值堆栈(不包括CompoundRoot)中的第一个对象上调用toString()

[1].foo - call getFoo() on the first object in the value stack starting from [OS:action] and excluding the CompoundRoot that supports a getFoo() method [1] .foo-从[OS:action]开始在值堆栈中的第一个对象上调用getFoo(),并排除支持getFoo()方法的CompoundRoot

ContextMap 上下文地图

ActionContext is the context in which an Action is executed. ActionContext是执行动作的上下文。 Each context is basically a container of objects an action needs for execution like the session, parameters, locale, etc. 每个上下文基本上都是一个容器,动作需要执行这些对象,例如会话,参数,语言环境等。

ActionContext.getContext().getContextMap();

give you access to the context map in which your are executing.Say for example you need to access Application Context than you can get access to that using the Map returned by above method 允许您访问正在执行的上下文映射。例如,您需要访问Application Context,然后才能使用上述方法返回的Map来访问该上下文

Update As pointed by @rees 更新如@rees所指出

context map of the ActionContext is pretty much the backing (context) map of the ValueStack ActionContext的上下文映射几乎是ValueStack的支持(上下文)映射

getContextMap() - Method in class com.opensymphony.xwork2.ActionContext Gets the context map. getContextMap() -com.opensymphony.xwork2.ActionContext类中的方法获取上下文映射。 This method gets the context map. 此方法获取上下文映射。

getValueStack() - Method in class com.opensymphony.xwork2.ActionContext Gets the OGNL value stack. getValueStack() -com.opensymphony.xwork2.ActionContext类中的方法获取OGNL值堆栈。 This method gets the current value stack for this request and returns the value stack.For detail about this method . 此方法获取此请求的当前值堆栈,然后返回值堆栈。有关此方法的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM