Struts2 ValueStack如何处理多个请求 [英] How does Struts2 ValueStack take care of multiple requests

查看:83
本文介绍了Struts2 ValueStack如何处理多个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解在Struts2中引入了 ValueStack ,并且Struts1模型的另一个更改现在是一个新的 ActionObject 被实例化对于每个请求。因此,我们可以定义实例变量而无需担心多线程问题。
拦截器和JSP从 ActionObjects 访问实例变量的方式是通过 ValueStack 。但 ValueStack 的实现方式(或至少由Struts2框架使用)的方式是 ValueStack 。使访问更容易,这样我们就不需要遍历整个对象树。我有以下问题。

I understand ValueStack was introduced in Struts2 and one more change from Struts1 model is now a new ActionObject is instantiated for each request. So we can define instance variables without worrying about multi threading issues. The way interceptors and JSPs access the instance variables from the ActionObjects is through the ValueStack. But the way ValueStack is implemented (or at least used by Struts2 framework) is by ValueStack. to make the access easier so that we don't need to traverse the whole object tree. I have following questions.


  1. 如果我有嵌入对象(多个对象层次结构)怎么办?在这种情况下,访问机制如何表现?

  1. What if I have embedded objects (multiple hierarchy of objects) ? how does the access mechanism behave in such a case?

如果让我们说2个客户端同时向同一个肌动蛋白发出请求并且结果为Action执行是不同的,因为2个客户提供的输入返回2个不同的结果。让我们说我的Action类有一个方法来获得最优惠的价格,并根据我的后端服务中的逻辑,结果出现在10和12两个不同的请求。现在 ActionClass 有一个名为price的成员变量,其中将存储此值,并且生成的JSP showResults.jsp 将访问这个变量(使用标签lib)来显示价格。 struts2框架如何保证client1和client2得到正确的响应,并且在JSP上显示响应时价格不会混乱,因为据我所知, ValueStack 刚进入先进先出(堆栈逻辑)时尚。因此,它可能最终会向两个客户端请求返回10,因为相同的变量在值堆栈上存储了两次(具有相同的名称)但具有不同的值。

If let us say 2 clients made requests to the same actin at the same time and the result of Action execution are different because the inputs provided by 2 clients came back with 2 different results. Let us say my Action Class has a method to get best price and based on the logic in my backend service the results come out as 10 and 12 for 2 different requests. Now ActionClass has a member variable called price in which this value will be stored and the resultant JSP showResults.jsp will access this variable (using a tag lib) to show the price. How does struts2 framework guarantee that client1 and client2 get the right response back and prices are not jumbled while the response is shown on the JSP because from what I understand the ValueStack just goes in first in first out (stack logic) fashion. So it might possibly end up returning 10 to both client requests as the same variable is stored twice (with the same name) on the value stack but with different values.

ValueStack 什么时候从列表中销毁对象?

When does the ValueStack destroy the object from its list?


推荐答案


  1. 嵌入式对象或换句话说,嵌套bean可以通过其访问者或在评估OGNL表达式时使用该访问者的OGNL直接访问。 Struts2在 valueStack top 上放置一个动作bean,因此动作属性按名称检索,但是嵌套的bean使用OGNL dot 表示法解析。有关OGNL的更多信息,请参阅文档

  1. Embedded objects or in other words nested beans are accessed directly via their accessors or via OGNL that used that accessors when evaluating OGNL expression. Struts2 places an action bean on the top of the valueStack, so the action properties are retrieved by name, but nested beans are resolved using OGNL dot notation. More about OGNL you can find in documentation.

每个动作实例都有自己的上下文和 valueStack ,因此客户端不会相互干扰除非在应用程序范围内维护这些值,否则它们有自己的值。

Each action instance has it's own context and valueStack, so the clients do not interfere with each other and have its own values unless the values are maintained in the application scope.

valueStack 由调度程序创建并放入操作上下文。它也可以在需要时由一些拦截器重新创建。您不应该担心它的值,因为它们在动作结束时被销毁。

The valueStack is created by the dispatcher and put to the action context. It also could be recreated by some interceptors when needed. You should not worry about its values because they are destroyed at the action end.

这篇关于Struts2 ValueStack如何处理多个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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