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<maganize> maganizeList = new ArrayList(){····};
<s:property value=“maganizeList.{?#this.price>18}.size()” />
<s:property value=“maganizeList.{?#this.name.contains(‘XXX’)}.size()” />
<s:iterator value=“maganizeList.{?#this.price>18}”/>
<s:property value=“name”/><s:property value=“price”/>
</s:iterator>
2.“%”显示声明OGNL表达式:用于某些标签中既能够接受字符,又能够接受OGNL表达式:
例如:<s:label label="#request.account" /> 会直接显示:#request.account出来
如果是:<s:label label="%{#request.account}" />就会是显示出account的值
3.“$”使用在配置文件中:AAA.xml都行
例如在struts.xml中:
<action name="" >
<result>·······?id=${id}</result>
</action>
额外的增加一点<s:if>的用法:
<s:if test="#parameters.name[0]==‘yao’">···</s:if>
<s:if test="name==‘yao’">···</s:if> 此处的name必须是action中的一个属性...