Access HashMap Using Struts 2

I have a hashmap that was created on a page using the struts2 tag <s:set>. It looks something like this.

<s:set var="mymap" value="#request.mymap"/>

At some point in the page, I need to get the value from the key based hash, and I want to do this using OGNL.

The key is created based on some logic, which I save using another tag <s:set>. Something like that

<s:set var="mykey" value="1">

I need to get the value from hashmap using this key. And I need to display it.

How to just call get function in hashmap?

I tried this

<s:property value="#mymap[#mykey]"/>

and this one

<s:property value="#mymap[%{#mykey}]"/>

and this one

<s:property value="%{#mymap[%{#mykey}}]"/>

The third, obviously, does not work due to the nesting problem. But the same nesting logic applies to the second case, due to the way the value attribute is handled. However, no one works for me.

, . , . , -, . - ognl .

, . , , - .

+3
1

, struts, , , % {}. jar. :

<s:property value="#mymap.[#mykey2]"/>

, href s:. % {} .

, , . .: >

Update: , - . http://mycodefixes.blogspot.com/2010/11/struts-2-creating-and-accessing-maps.html

+3

Source: https://habr.com/ru/post/1771044/


All Articles