在Struts 2中使用OGNL访问变量的不同方法是什么 [英] What are different ways to access variables with OGNL in Struts 2

查看:62
本文介绍了在Struts 2中使用OGNL访问变量的不同方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用OGNL的Struts2项目中工作.我看到了使用OGNL在JSP中访问数据的三种不同方式.

I am working now in a Struts2 project which uses OGNL. I see three different ways to access data in JSP using OGNL.

value1 ="previousList"
value2 = "#previousList"
value3 = "%{previousList}"

这些将做什么,还有其他方法可以从OGNL访问数据吗?

What these will do and are there other ways to access data from OGNL?

推荐答案

值堆栈,它是

The value stack which is an implementation of ValueStack has two methods push and set. The first method pushes the variable to the stack, but the second sets in to the value stack's context. If the variable in the value stack's context, you can use different ways to access it. Struts has a feature if it can't find a variable in the value stack it searches the value stack's context.

<s:property value="previousList"/>
<s:property value="#previousList"/>
<s:property value="%{previousList}"/>


因此,它们所有人都打印该值,但是第二种情况要快一些,因为它使用#指出OGNL来直接在OGNL上下文中查找值.查看有关 Struts文档中的OGNL 的更多信息.


So, all of them print the value, but second case is a bit faster because it points out OGNL using # to find the value directly in the OGNL context. See more about OGNL in Struts docs.

另一方面,如果变量不在上下文中,而是在值堆栈的根中,则第二个方法将无法返回该值.

On the other hand if the variable is not in the context but in the value stack's root the second method fails to return the value.

最后一点是Struts解析其一些标记属性(几乎所有),例如OGNL的 value ,而%{} 定义了OGNL表达式的范围.

And the last point is that Struts parses its some tag attributes (almost all), like value, for OGNL, and %{} defines the scope of OGNL expression.

这篇关于在Struts 2中使用OGNL访问变量的不同方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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