List<String> cityList =
new
ArrayList<String>();
cityList.add(
"Washington DC"
);
cityList.add(
"Delhi"
);
cityList.add(
"Berlin"
);
cityList.add(
"Paris"
);
cityList.add(
"Rome"
);
request.setAttribute(
"cityList"
, cityList);
<c:forEach var=
"city"
items=
"cityList"
>
<b> ${city} </b>
</c:forEach>
Iterate a Hashmap
Map<String, String> countryCapitalList = new HashMap<String, String>();
countryCapitalList.put( "United States" , "Washington DC" );
countryCapitalList.put( "India" , "Delhi" );
countryCapitalList.put( "Germany" , "Berlin" );
countryCapitalList.put( "France" , "Paris" );
countryCapitalList.put( "Italy" , "Rome" );
request.setAttribute( "capitalList" , countryCapitalList);
<c:forEach var= "country" items= "${capitalList}" >
Country: ${country.key} - Capital: ${country.value}
</c:forEach>
|
0 comments:
Post a Comment