struts2中 # % $ 的区别和用法
来源:互联网 发布:dota2台词 知乎 编辑:程序博客网 时间:2024/05/29 11:24
struts2 OGNL,struts2 表达式语言,Struts2 中OGNL表达式的用法,Struts2 #,表达式语言的好处,Struts2 $,struts2 井号,星号,百分号
表达式语言主要有以下几大好处:
1. 避免(MyType) request.getAttribute()和myBean.getMyProperty()之类的语句,使页面更简洁;
2. 支持运算符(如+-*/),比普通的标志具有更高的自由度和更强的功能;
3. 简单明了地表达代码逻辑,使用代码更可读与便于维护。
Struts2 中OGNL表达式的用法:
OGNL(Object-Graph Navigation Language),可以方便地操作对象属性的开源表达式语言;
“#”主要有三种用途:
1. 访问OGNL上下文和Action上下文,#相当于ActionContext.getContext();下表有几个ActionContext中有用的属性:
名称 作用 例子
parameters 包含当前HTTP请求参数的Map #parameters.id[0]作用相当于request.getParameter("id")
request 包含当前HttpServletRequest的属性(attribute)的Map #request.userName相当于request.getAttribute("userName")
session 包含当前HttpSession的属性(attribute)的Map #session.userName相当于session.getAttribute("userName")
application 包含当前应用的ServletContext的属性(attribute)的Map #application.userName相当于application.getAttribute("userName")
attr 用于按request > session > application顺序访问其属性(attribute) #attr.userName相当于按顺序在以上三个范围(scope)内读取userName属性,直到找到为止
2. 用于过滤和投影(projecting)集合,如books.{?#this.price<100};
3. 构造Map,如#{'foo1':'bar1', 'foo2':'bar2'}。
“%”符号的用途是在标签的属性值被理解为字符串类型时,告诉执行环境%{}里的是OGNL表达式。
var
当index变量为1时,语句就会被当作var
<s:url
这说明struts2里不同的标签对ognl的表达式的理解是不一样的。如果当有的标签“看不懂”类似“#myMap['key1']”的语句时,就要用%{}来把这括进去,“翻译”一下了。
“$”有两个主要的用途 :
1. 用于在国际化资源文件中,引用OGNL表达式,例子请参考《在Struts 2.0中国际化(i18n)您的应用程序》
2. 在Struts 2配置文件中,引用OGNL表达式,如
<action name="AddPhoto" class="addPhoto">
<interceptor-ref name="fileUploadStack" />
<result type="redirect">ListPhotos.action?albumId=${albumId}</result>
</action>
- struts2中 # % $ 的区别和用法
- struts2中 # % $ 的区别和用法
- struts2中 # % $ 的区别和用法
- struts2中 # % $ 的区别和用法
- struts2中 # % $ 的区别和用法
- struts2中 # % $ 的区别和用法
- struts2中 # % $ 的区别和用法
- struts2中 # % $ 的区别和用法
- struts2中#,%的用法区别?
- struts2中 # % $ (井号,星号,百分号)的区别和用法
- struts2中 # % $ (井号,星号,百分号)的区别和用法
- struts2中 # % $ (井号,星号,百分号)的区别和用法
- struts2中 # % $ (井号,星号,百分号)的区别和用法
- struts2中#,%,$用法区别?
- struts1和struts2中Action的区别
- struts2中redirect和redirectAction的区别
- struts2中redirect和redirectAction的区别
- struts2中#$%的用法
- UITableView性能优化及使用总结
- poj 1177 || HDU 1828 Picture (线段树扫描线求 图形并的周长)
- 第2章 10
- 一个有趣的问题:ls -l显示的内容中total到底是什么?
- POJ1236—— Network of Schools
- struts2中 # % $ 的区别和用法
- NopCommerce多商城设置
- 第一次FLEX实验单新鲜出炉
- poj 3907 Build Your Home 多边形面积
- android开发 - Widgets窗口小部件
- 用Java语言实现二叉树删除结点
- leetcode || 60、Permutation Sequence
- poj 2796 Feel Good
- C++易忽略点