Anas
Anas

Reputation: 21

can not display value of HashMap in JSTL in Spring MVC application

I don't understand why value of map is not displayed in JSP.

Controller side:

.....
List<String> codes=new ArryList<String>();
codes.add("DATA_BASE");
codes.add("CSV_FILE");
codes.add("WEB_SERVICE");
model.addAttribute("codes",codes);
.....
Map<String,String> labelsMap=new HashMap<String,String>();
labelsMap.put("DATA_BASE","Data base");
labelsMap.put("CSV_FILE","CSV file");
labelsMap.put("WEB_SERVICE","Web service");
model.addAttribute("labelsMap",labelsMap);
....

View side:

<c:forEach var="code" items="${codes}" >
code is: <c:out value="${code}">
value is: <c:out value="${labelsMap[code]}">
</c:forEach>

Result:

code is: DATA_BASE
value is: 

code is: CSV_FILE
value is: 

code is: WEB_SERVICE
value is: 

Values of labelsMap are not displayed.

Upvotes: 0

Views: 100

Answers (1)

holi-java
holi-java

Reputation: 30696

how about this? what expression language you are using? EL or OGNL?

<c:out value="${labelsMap["${code}"]}">

Upvotes: 1

Related Questions