OGNL表达式是(Object-Graph Navigation Language)是对象图形化导航语言。OGNL是一个开源的项目,struts2中默认使用OGNL表达式语言来显示数据。
iterator标签
用途:主要用于迭代,可以迭代List,Set,Map,Array
1把集合放到对象栈
Person person1=new Person();person1.setName("xx");
person1.setAge(4);
Person person2=new Person();
person2.setName("hh");
person2.setAge(5);
List<Person> list=new ArrayList<Person>();
list.add(person1);
list.add(person2);
ActionContext.getContext().getValueStack().push(list);
迭代:
<s:iterator>
<s:property value="name"/>
<s:property value="age"/>
</s:iterator>
value中写的是放入对象栈的集合名,在栈顶的一定不能写。
2把集合放入map中
ActionContext.getContext().put("list",list);
迭代:
<s:iterator value="#list">
<s:property value="name"/>
<s:property value="age"/>
</s:iterator>
3把集合放入request中
ActionContext.getContext().getRequest.setAttribute("list",list);
迭代:
<s:iterator value="#request.list">
<s:property value="name"/>
<s:property value="age"/>
</s:iterator>
“%”符号的用途
是在标签的属性值给理解为字符串类型时,执行环境%{}中添加的是OGNL表达式。