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

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

问题描述

我目前正在使用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标签内有效.在评估OGNL表达式时,应使用IMO,尽管它通常是可选的.但是,何时是可选的.通常,buuuut并非总是如此.最好使用它,并且要露骨和交流.

      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 #.

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

      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天全站免登陆