0

我可以通过ValueStack多种方式设置属性。

 ValueStack stack = ActionContext.getContext().getValueStack();
 stack.getContext().put("resultDTO",resultDTO);  //1. creates a different branch 
 //parallel to root

 stack.set("resultDTO", resultDTO); //2. pushes on root as a Map?
 stack.push(resultDTO); //3. pushes on root
 myActionClass.setProperty(); //4. normal action accessor

我需要能够在 JSP、freemarker 和 java 中取回所有这些值

 stack.findValue() or stack.findString().    

我想了解这 4 种设置方法中的每一种的生命周期。是否跨应用程序。是否为每个请求创建了ValueStack,并为每个请求在其中设置了应用程序和会话值?

我知道第 4 种方法是最常用的方法,但我可能不会在所有不容易访问操作类的地方都使用它。

我对在 JSP 中访问还有另一个疑问

 <s:push value="resultDTO" ><s:property value="data.form1[0]" /></s:push>
 <!--5.works for context.put() & stack.set() both-->

 <s:property value="#resultDTO.data.form1[0].countryofissue" /> <!--6.context.put()-->
 <s:property value="resultDTO.data.form1[0].countryofissue" />  <!--7.stack.set()-->
 <s:property value="data.form1[0].countryofissue" />            <!--8.stack.push()-->

我也想知道第 5 点在stack.getContex().put()和中是如何工作的stack.set()?我知道在第 6层,我正在访问的resultDTO是一个不同的根目录,而在第 7 层,它是默认根目录的子节点,即 ValueStack。在 8th 它开始从默认根搜索。

我浏览了http://struts.apache.org/2.0.11.1/docs/ognl.htmlhttp://struts.apache.org/2.1.2/struts2-core/apidocs/com/opensymphony/xwork2/util /ValueStack.html并且相当混淆这个链接http://www.opensymphony.com/ognl/html/DeveloperGuide/introduction.html#embeddingOGNL

说了所有这些后,我不太倾向于使用stack.getContext().put()方法,因为通过将 url 设置为?debug=browser可以清楚地看到其中的值。如果我出错了,请告诉我。

4

1 回答 1

0

ValueStack是每个请求。如果您将值放在堆栈上,它们可以在请求的后期(即在视图层)中访问,但不会在重定向中存活,这将是一个新的 HTTP 请求并且有自己的ValueStack.

在正常情况下,URL 或表单帖子中的参数将使用操作的 setter 方法设置在操作上。在拦截器中,您可以将值直接添加到堆栈中。例如,ExceptionMappingInterceptor使用该stack.push(Object)方法发布异常以在错误页面上使用。

  • stack.getContext().put(String, Object)-- 将键/值放置在堆栈上的映射中。该映射表示堆栈的上下文。
  • stack.set(String, Object)-- 将键/值放置在堆栈上的映射中。我不确定这与以前的方法有何关系,除了它是不同的地图。
  • stack.push(Object)-- 这会将对象放在堆栈的根部。

You shouldn't need to place anything on the stack from within the view layer, so I'm curious what you are trying to do that necessitates that.

于 2011-02-18T17:31:12.097 回答