将对象直接存储到ValueStack/ActionContext的目的是什么? [英] What's the purpose of storing objects directly to the ValueStack/ActionContext?

查看:114
本文介绍了将对象直接存储到ValueStack/ActionContext的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的研究,我已经看到诸如<s:set><s:push>或通过创建<s:bean>之类的标签能够直接将引用插入到ActionContextValueStack.这让我很困惑,因为为什么您不能仅拥有一个专用的位置来存储所有东西?可能只是将所有内容都放在ActionContext中,因为它基本上起了ServletContext的作用.

Based from what I've researched, I've seen that tags such as <s:set>, <s:push> or by creating an <s:bean> are able to insert references directly to the ActionContext or ValueStack. This confuses me a lot because why can't you just have one dedicated place to store everything? Probably just put everything in the ActionContext since it's basically acts as a ServletContext.

为了使其更加混乱,如果您想访问ValueStack中的值,则必须使用诸如<s:property>的Struts标记,但是如果该值只是存储在ActionContext中,则只需使用OGNL提供的#value前缀.

To make it even more confusing, if you wanted to access values in the ValueStack, you'll have to use Struts tags such as <s:property> but if the value's just stored in the ActionContext, you just use the #value prefix provided by OGNL.

有人可以帮我清理一下吗?当我使用Spring时,我相信我需要的所有内容(请求,会话,applicationContext)都在ServletContext内部,并且可以在我的网页上访问这些值,我可以仅使用$前缀来访问上下文中的任何内容.

Can someone please clear this up for me? When I used Spring, I believe everything that I needed (request, session, applicationContext) was inside the ServletContext and to access these values on my webpage, I could just use the $ prefix to access anything within context.

推荐答案

每个地方都有其专用存储空间,您可以在其中放置对象,以供以后在某些调用上下文中运行时使用/获取对象.无论运行什么上下文,框架都是关联的.上下文是您可以使用Java或其他表达语言(EL)(如OGNL)访问的内部范围对象之间进行通信的方式.

Every place has its dedicated storage where you can put your objects for later use/retrieve running across some invocation context. Whatever context is running the framework is associated. The context is the way of communicating between scoped objects inside it you can access using Java or other expression language (EL) like OGNL.

在OGNL中,操作上下文是OGNL上下文,值堆栈是根.

In OGNL the action context is the OGNL context, and the value stack is a root.

该框架将OGNL上下文设置为我们的ActionContext,并且 值堆栈作为OGNL根对象. (值栈是一组 多个对象,但对OGNL来说,它似乎是单个对象.) 通过值堆栈,框架将其他对象放置在 ActionContext,包括代表应用程序,会话, 并请求上下文.这些对象共存于ActionContext中, 值堆栈(我们的OGNL根目录)旁边.

The framework sets the OGNL context to be our ActionContext, and the value stack to be the OGNL root object. (The value stack is a set of several objects, but to OGNL it appears to be a single object.) Along with the value stack, the framework places other objects in the ActionContext, including Maps representing the application, session, and request contexts. These objects coexist in the ActionContext, alongside the value stack (our OGNL root).

ActionContextThreadLocal,因此您可以在一个线程中使用它.从此线程获取操作上下文/值堆栈的最佳方法是使用静态方法.

The ActionContext is ThreadLocal, so you can use it in one thread. The best way to get the action context/value stack from this thread is using static method.

ActionContxt ctx = ActionContext.getContext();
ValueStack vs = ctx.getValueStack();

拦截器还传递了一个参数,称为调用上下文,即操作上下文.

Interceptors also have a parameter passed, known as invocation context, which is the action context.

值堆栈也有其自己的上下文,验证也有其自己的上下文.因此,这些定义永无止境.

The value stack has also its own context, the validation has its own context. So, these definitions never end.

这篇关于将对象直接存储到ValueStack/ActionContext的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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