struts中的取map和list & jsp中取map和list
<%
List list = new ArrayList();
list.add("a");
list.add("b");
list.add("c");
request.setAttribute("l1",list); Map map = new HashMap() ;
map.put("a","a");
map.put(1L,"b"); //这里的1要强转成long类型,因为el表达式的数字都是long类型
request.setAttribute("m1",map); %>
<!--上面已经压入了了值栈中-->
<s:debug ></s:debug>
<br/>
[原EL表达式取值list,map]
<br/>
list:
${l1[0]}
${l1[1]}
${l1[2]}
</br>
map:
${m1["a"]}
${m1[1]}
<br/>
[struts2中取值]
<br/>
map两种:
<s:iterator value="#request.m1" id="name">
<s:property value="key"/>=<s:property value="value"/> </s:iterator>
<br/>
<s:iterator value="#request.m1" id="name" var="var">
<s:property value="#var.key"/>=<s:property value="#var.value"/> </s:iterator>
<hr/>
list:
<s:iterator value="#request.l1" id="name" var="var" status="s">
<!-- iterator是循环迭代,添加一个条件若该元素的索引是1,则打印出这个元素的值-->
<s:if test="#s.getIndex()==1">
<s:property value="#var"/>
</s:if>
</s:iterator>
页面输出结果
struts中的取map和list & jsp中取map和list
[原EL表达式取值list,map]
list: a b c
map: a b
[struts2中取值]
map两种: 1=b a=a
1=b a=a
list: b