How to concatenate 2 action class variables in Struts 2?

China☆狼群 提交于 2019-12-11 16:46:19

问题


I have 2 variable in my action class, id1 and id2. Joined by a _, they're used as a map key.

I am not able to retrieve the map value using this code:

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

How should I retrieve the map value?


回答1:


The expression id1_id2 in OGNL will assume the presence of a variable named id1_id2, since it's a perfectly legal identifier.

If you want to concatenate strings, you'd need:

<s:property value="%{mymap[id1 + '_' + id2]}" />

I'd likely create a separate variable to use as the key:

<s:set var="mapKey" value="%{id1 + '_' + id2}" />
<s:property value="%{mymap[#mapKey]}" />

Or more likely, I'd do it somewhere besides the view layer.



来源:https://stackoverflow.com/questions/8242704/how-to-concatenate-2-action-class-variables-in-struts-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!