我可以通过多种方式在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是否创建了每个请求,并为每个请求设置了应用程序和会话值?
我知道第四种方法是最常见的方法,但我可能并不是在所有地方都使用这种方法,因为在这些地方,动作类是不容易访问的。
我对在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()-->我还想知道在stack.getContex().put()和stack.set()中第5点是如何工作的?我知道,在第六个resultDTO中,我正在访问的是一个不同的根,而在第七个,它是默认根的子根,即ValueStack。在第8页,它开始从默认根目录中搜索。
我浏览了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来清楚地看到其中的值。如果我做错了,请告诉我。
发布于 2011-02-18 17:31:12
ValueStack是按请求进行的.如果将值放置在堆栈上,则可以在请求的后面(即视图层)访问这些值,但重定向(这将是一个新的ValueStack请求并拥有自己的HTTP )将无法存活。
在正常情况下,URL或表单post中的参数将使用操作的setter方法在操作上设置。在拦截器中,可以将值直接添加到堆栈中。例如,ExceptionMappingInterceptor使用stack.push(Object)方法发布异常,以便在错误页上使用。
stack.getContext().put(String, Object) --将键/值放置到堆栈上的映射中。该映射表示stack.stack.set(String, Object)的上下文--将键/值放置到堆栈上的映射中。我不确定这与前面的方法有什么关系,只是它是一个不同的map.stack.push(Object) --它将对象放置在堆栈的根上.您不需要从视图层中在堆栈上放置任何东西,所以我很好奇您想要做什么,这就必须这样做。
https://stackoverflow.com/questions/5037561
复制相似问题