How to get the value of a card based on a key in JSP?

I have a Struts 2 application using the JSTL / Struts2 / DisplayTag tag libraries in my JSP. Is there a way to access the map value in the JSP using a key?

// Action code
Map<String,String> map = new HashMap<String,String>();

mapOnValueStack = map;

//add key/value pairs

fieldKeyOnValueStack = "1";//sets key

....

<%-- JSP code --%>

<s:property value="%{mapOnValueStack.get(fieldKeyOnValueStack)}" />

Essentially, I want to make access to the map in JSP. Is it possible?

Thank!

+3
source share
4 answers

Have you tried this:

<s:property value="%{mapOnValueStack.['fieldKeyOnValueStack']}" />
+7
source

If you used it in your action,

Map<String,Integer> headerMap=new HashMap<String, Integer>();
headerMap.put("INITIATED", 0);
headerMap.put("COMPLETED", 0);
headerMap.put("SUBMITTED", 0);
headerMap.put("APPROVED", 0);
headerMap.put("TRAFICKED", 0);
headerMap.put("REJECTED", 0);

Then use this on jsp,

<s:property value="%{headerMap.INITIATED}" />
<s:property value="%{headerMap.REJECTED}" />
+4
source

try it

<s:property value="%{mapOnValueStack['fieldKeyOnValueStack']}" />
+2
source

try it

<c:forEach var="entry" items="${mapOnValueStack}">
    Name:  ${entry.key} <br/>
    Value: ${entry.value}
</c:forEach>

Hope this works.

-4
source

All Articles