el表达式跟ognl表达式的区别(用法和页面取值)
来源:互联网 发布:windows 10开机扬声器 编辑:程序博客网 时间:2024/05/29 03:47
1.区别
用法区别:OGNL是通常要结合Struts 2的标志一起使用,如<s:property value="#xx" /> struts页面中不能单独使用,el可以单独使用 ${sessionScope.username}
页面取值区别:
名称
servlet
ognl el
parameters
request.getParameter("username")
#username ${username}
request
request.getAttribute("userName")
#request.userName ${requestScope.username}
session
session.getAttribute("userName")
#session.userName ${sessionScope.username}
application
application.getAttribute("userName")
#application.userName ${applicationScope.username}
attr
用于按request > session > application顺序访问其属性(attribute)
#attr.userName相当于按顺序在以上三个范围(scope)内读取userName属性,直到找到为
2.ognl讲解
OGNL是Struts 2默认的表达式语言。是Object Graphic Navigation Language(对象图导航语言)的缩写,它是一个开源项目。
1.#符号的用途一般有三种。
1)访问非根对象属性,例如示例中的#session.msg表达式,由于Struts 2中值栈被视为根对象,所以访问其他非根对象时,需要加#前缀。实际上,#相当于ActionContext.getContext();;#session.msg表达式相当于ActionContext.getContext().getSession(). getAttribute(”msg”) 。
2)用于过滤和投影(projecting)集合,如示例中的persons.{?#this.age>20}。
3)用来构造Map,例如示例中的#{’foo1′:’bar1′, ’foo2′:’bar2′}。
2.%符号
%符号的用途是在标志的属性为字符串类型时,计算OGNL表达式的值。如下面的代码所示:
构造Map
- <s:set name=”foobar” value=”#{’foo1′:’bar1′, ‘foo2′:’bar2′}” />
- <p>The value of key “foo1″ is <s:property value=”#foobar['foo1']” /></p>
- <p>不使用%:<s:url value=”#foobar['foo1']” /></p>
- <p>使用%:<s:url value=”%{#foobar['foo1']}” /></p>
- <s:set name=”foobar” value=”#{’foo1′:’bar1′, ‘foo2′:’bar2′}” />
- <p>The value of key “foo1″ is <s:property value=”#foobar['foo1']” /></p>
- <p>不使用%:<s:url value=”#foobar['foo1']” /></p>
- <p>使用%:<s:url value=”%{#foobar['foo1']}” /></p>
3.$符号
$符号主要有两个方面的用途。
在国际化资源文件中,引用OGNL表达式,例如国际化资源文件中的代码:reg.agerange=国际化资源信息:年龄必须在${min}同${max}之间。
在Struts 2框架的配置文件中引用OGNL表达式,例如下面的代码片断所示:
- <validators>
- <field name=”intb”>
- <field-validator type=”int”>
- <param name=”min”>10</param>
- <param name=”max”>100</param>
- <message>BAction-test校验:数字必须为${min}为${max}之间!</message>
- </field-validator>
- </field>
- </validators>
- <validators>
- <field name=”intb”>
- <field-validator type=”int”>
- <param name=”min”>10</param>
- <param name=”max”>100</param>
- <message>BAction-test校验:数字必须为${min}为${max}之间!</message>
- </field-validator>
- </field>
- </validators>
- el表达式跟ognl表达式的区别(用法和页面取值)
- el表达式跟ognl表达式的区别(用法和页面取值)
- el表达式跟ognl表达式的区别(用法和页面取值)
- el表达式跟ognl表达式的区别(用法和页面取值)
- el表达式跟ognl表达式的区别(用法和页面取值)
- el表达式跟ognl表达式的区别(用法和页面取值)
- el表达式跟ognl表达式的区别(用法…
- el表达式跟ognl表达式的区别
- el表达式跟ognl表达式的区别
- el表达式跟ognl表达式的区别
- el表达式跟ognl表达式的区别
- el表达式跟ognl表达式的区别
- el表达式跟ognl表达式的区别
- el表达式跟ognl表达式的区别
- EL表达式和OGNL表达式的区别
- el表达式和ognl表达式的区别
- el表达式跟ognl表达式的区别(转)
- [20150911]el表达式跟ognl表达式的区别
- My97DatePicker日期控件的用法
- Visual Studio SDK介绍
- 中位数
- CMake 指定gcc编译版本
- Android-广播接收者:发送有序广播
- el表达式跟ognl表达式的区别(用法和页面取值)
- 嵌入式系统学习——STM32之UCOS-III事件标志组和存储管理
- ConsumerCoordinator分析
- 正则表达式全部符号
- 委托初体验
- word使用技巧---插入图片显示不全的解决方案
- 安卓仿IOS删除抖动动画
- mysql主从复制(五)
- Java 驼峰命名法