#{} ${} 和 %{} 之间有什么区别? [英] what's the difference between #{} ${} and %{}?

查看:96
本文介绍了#{} ${} 和 %{} 之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 struts2,我只是不明白 ${var}#{var} 之间的区别是什么>%{var} 它们是不同的范围吗?他们是什么?

I'm currently working with struts2, and I just don't understand what the difference is between ${var}, #{var}, and %{var} are they different scopes? what are they?

我发现了一个#:

<s:select label="Year"
      id="%{param.name}"
      list="#{'2010':'2010','2011':'2011','2012':'2012','2013':'2013','2014':'2014', '2015':'2015'}"
      value="%{currentYear}"
      required="true"
/>

这里看起来像是一个关联数组,但有时我将其视为 #var(没有括号)有什么想法吗?

here it looks like it's an associative array, but there's other times I've seen it as #var (without the brackets) any ideas?

推荐答案

  • ${} - 标准 JSP EL 表示法.
  • #{} - 标准 UEL 表示法;没用过,可能有用.
  • %{} - OGNL 表达式符号.
    • ${} - Standard JSP EL notation.
    • #{} - Standard UEL notation; never used it, may work.
    • %{} - OGNL expression notation.
    • JSP EL 表示法之所以有效,是因为有一个请求包装器会首先遵循值堆栈进行查找,然后如果在值堆栈中找不到值,则回退到正常的 JSP 评估.

      JSP EL notation works because there's a request wrapper that will defer to the value stack for lookups first, then fall back to the normal JSP evaluation if there's no value found on the value stack.

      OGNL 表达式符号仅在 S2 标签内有效.IMO 应该在您评估 OGNL 表达式时使用它,尽管它通常是可选的.它是可选的,但是有点废话.它通常是,但并非总是如此.最好使用它,并且要明确且易于沟通.

      OGNL expression notation is valid only within S2 tags. IMO it should be used whenever you are evaluating an OGNL expression, although it is quite often optional. When it is optional is somewhat of a crap shoot, however. It often is, buuuut not always. Best to use it and be explicit and communicative.

      可能询问# 变量,例如#session 等.# 用于解析位于地图"部分的值堆栈上的值.我将值堆栈视为堆栈和作用域的组合:如果一个对象已被压入堆栈,则不需要 #.如果一个值已经创建,你需要#.

      You may be asking about # variables, like #session etc. # is used to resolve a value on the value stack that's in the "map" portion. I view the value stack as a combination stack and scope: if an object has been pushed on the stack, you don't need the #. If a value has been created, you need the #.

      例如,如果您使用 创建变量,则必须使用 # 前缀访问它,例如:

      For example, if you use <s:set> to create a variable, you must access it using a # prefix, like:

      <s:set var="foo" value="'plugh'"/>
      <s:property value="#foo"/>
      

      这篇关于#{} ${} 和 %{} 之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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