How you can fetch the value from the map based on key without iterating over it in Struts 2?

Struts2Logo

Struts 2 makes extensive use of OGNL in order to retrieve the values of elements. OGNL stands for Object Graph Navigation Language. As the name suggests, OGNL is used to navigate an object graph. In this post, i am going to use the OGNL syntax to  fetch the value from the map based on key  on a jsp page.
For that i am going to use get('key') mehtod over a map.Here is the example:
<s:property value="%{Map.get('SMS')}"/>

Another Case:
Assume that you have a variable in page scope called "myKey" that you set using the  s:set tag. The value of this variable is a string key that can be used to get a value from a map.

Here is how you can fetch the value from the map without iterating over it.
<s:set value="'key_1'" var="myKey"></s:set>
<s:property value="%{#request.myMap[#myKey]}">
</s:property>
Share on Google Plus

About JK STACK

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment