【 tulaoshi.com - Web开发 】
                             
                            在方括号中指定键,并将相应的值作为表达式的值返回。例如,表达式 ${map['key']} 返回与 map标识符所引用的 Map 中的 "key" 键相关联的值。 
当forEach 的items属性中的表达式的值是java.util.Map时,则var中命名的变量的类型就是 java.util.Map.Entry。这时var=entry的话,用表达式${entry.key}取得键名。 用表达${entry.value}得到每个entry的值。这是因为java.util.Map.Entry对象有getKey和getValue方法,表达式语言遵守JavaBean的命名约定。
% 
MapString,String map2 = new HashMap(); 
map2.put("a","hello world"); 
map2.put("b","this is map"); 
request.setAttribute("map2",map2); 
% 
br 
键值对遍历br 
c:forEach var="item" items="${map2}" 
${item.key}  ${item.value} br 
/c:forEach 
键遍历br 
c:forEach var="item" items="${map2}" 
${item.key}br 
/c:forEach 
值遍历br 
c:forEach var="item" items="${map2}" 
${item.value}br 
/c:forEach 
body 
brbr 
% 
ListString list = new ArrayListString(); 
list.add("first"); 
list.add("second"); 
ListString list2 = new ArrayListString(); 
list2.add("aaaaaa"); 
list2.add("bbbbbb"); 
MapString,ListString map = new HashMap(); 
map.put("a",list); 
map.put("b",list2); 
request.setAttribute("map",map); 
% 
通过键获得列表值,并遍历列表br 
c:forEach var="item" items="${map['a']}" 
${item }br 
/c:forEachbr 
c:forEach var="item" items="${map['b']}" 
${item }br 
/c:forEach br 
map中值为列表,直接遍历列表中的每一项br 
c:forEach var="item" items="${map}" 
c:forEach items="${item.value}" var="it" 
${it }br 
/c:forEach 
/c:forEach