1.“#”用于声明OGNL表达式,有3种用途:
一.能够访问OGNL的上下文和ActionContext资源,相当于ActionContext.getContext();
1.#parameters,代表request.getParameterValues("id");返回String[]类型,一般使用#parameters.id[i];
2.#request,代表request.getAttribute("account");相当于#request.account;
3.#session,代表session.getAttribute("account");相当于#session.account;
4.#application,代表application.getAttribute("account");相当于#application.account;
5.#attr,代表request,session,application里面所有的属性,#attr.account相当于EL表达式中的${account},依次查看request,session,application,找到为止.
二.用于过滤或筛选集合,例如:books.{?#this.price<20};
三.构造Map,如#{‘foo1’:‘bar1’,‘foo2’:‘bar2’};
例子:
maganize是javabean类,里面有属性{String name,int price};
Action中有List
maganizeList = new ArrayList(){····};
value=“maganizeList.{?#this.price>18}.size()”
/>
value=“maganizeList.{?#this.name.contains(‘XXX’)}.size()”
/>
value=“maganizeList.{?#this.price>18}”/>
value=“name”/>
value=“price”/>
2.“%”显示声明OGNL表达式:用于某些标签中既能够接受字符,又能够接受OGNL表达式:
例如:
/> 会直接显示:#request.account出来
如果是:
/>就会是显示出account的值
3.“$”使用在配置文件中:AAA.xml都行
例如在struts.xml中:
·······?id=${id}
额外的增加一点的用法:
test="#parameters.name[0]==‘yao’">···
test="name==‘yao’">···
此处的name必须是action中的一个属性...