我可以通过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.html,http://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可以清楚地看到其中的值。如果我出错了,请告诉我。