Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Map value given a key in a JSP?

Tags:

java

jsp

struts2

I have a Struts 2 application using the JSTL/Struts2/DisplayTag tag libraries in my JSP. Is there a way to access the value of a Map in a JSP given the 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 do map access within the JSP. Is this possible?

Thanks!

like image 250
Nick Avatar asked Jan 21 '23 06:01

Nick


1 Answers

Did you try this :

<s:property value="%{mapOnValueStack.['fieldKeyOnValueStack']}" />
like image 104
Michael Zilbermann Avatar answered Feb 01 '23 10:02

Michael Zilbermann