Java開発EL(Expression Language)式を利用してMAP Listの値を取得する

1.EL式–MAP

1.1 actionコード:
Map map = new HashMap();
map.put(key1,value1);
map.put(key2,value2);
map.put(key3,value3);

1.2 JSP画面
<forEachitems="${map}" var="item">
<c:outvalue="${item.key}"/>
<c:outvalue="${item.value}"/>
</forEach>

2.EL式–List
2.1 actionコード
List list = new ArrayList();
list.add(“study");
list.add(“map skill");
list.add(“welcome");
list.add(“startnews24");

書き方2
List<Map<String,Object>> employees = new ArrayList<Map<String,Object>>();
Map<String,Object> s1 = new HashMap<String,Object>();
s1.put(“name","yamada");
s1.put(“age","35″);
employees.add(s1);
Map<String,Object> s2= new HashMap<String,Object>();
s2.put(“name","oohara");
s2.put(“age","32″);
employees.add(s2);

2.2 サンプルコード
<c:forEach var ="employee" items ="$ {employees}" >
<c:out value="$ {employee.name}" default="wang"/> </td>
<c:out value="$ {employee.age}" default="wang"/>
</c:forEach>

Software

Posted by arkgame